
CSS Font Properties: Family, Style, Variant, Weight, and Size
11/10/2019
The CSS Box Model: Content, Padding, Borders, and Margin
11/10/2019
Start with an ordered or unordered HTML list. CSS can change the marker’s appearance, its position, and the spacing while preserving the original list structure.
8. CSS list properties
| Property | Description | Values |
|---|---|---|
list-style-type | Style of visual markers or bullets | disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none |
list-style-image | Image used as a list marker | url() | none |
list-style-position | Position of the marker | inside | outside |
list-style | Sets multiple list styles in a single declaration | list-style-type | list-style-position | list-style-image |
8.1. Marker type with list-style-type
Use disc, circle, or square for unordered lists. Common ordered markers include decimal, lower-alpha, and upper-roman. The value none removes the visible marker.
.a {list-style-type: circle;}
.b {list-style-type: square;}
.c {list-style-type: upper-roman;}
.d {list-style-type: lower-alpha;}8.2. Marker image with list-style-image
Use a small image as the marker. Set list-style-type as a fallback so the list still has a marker if the image cannot load.
ul.a { list-style-image: url('images/animated-bullet.gif'); }
ul.b { list-style-image: url('https://media.giphy.com/media/tBik70kZOJKOk/giphy.gif'); }8.3. Marker position with list-style-position
Outside places the marker outside the item’s main block, so wrapped lines line up with the text. Inside puts the marker into the flow of the first line. Compare both values with a long list item.
ul.a { list-style-position: outside; }
ul.b { list-style-position: inside; }8.4. List shorthand with list-style
Set marker type, position, and image together. This example uses a square marker outside the text. Omitted components reset to their initial values.
ul.a { list-style: square outside; }
ul.b { list-style: circle inside; }8.5. Emoji markers with ::before
Remove the default marker and padding with list-style: none and padding: 0. Add an emoji through the li::before pseudo-element and give it a right margin to separate it from the text. Keep essential meaning in the text of the item.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lists with emoji markers</title>
<style>
ul {
list-style: none; /* Remove the default markers */
padding: 0; /* Remove the default padding */
}
li::before {
content: '😊'; /* Use an emoji as a marker */
margin-right: 10px; /* Space between the emoji and item text */
}
</style>
</head>
<body>
<h1>Lists with emoji markers</h1>
<ul role="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</body>
</html>8.6. Background image markers with background-image
When you need precise control over size and alignment, turn off the default marker and create an inline-block li::before with empty content. Set its width and height, load the image through background-image, and use background-size: contain to preserve the image proportions. Add a right margin between the marker and the text. In Safari, removing list styling can affect how an unordered list is announced. Use role=”list” on the list if testing shows that its semantics are lost.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>List with image markers</title>
<style>
ul {
list-style: none; /* Remove the default markers */
padding: 0; /* Remove the default padding */
}
li::before {
content: ""; /* Use empty generated content */
display: inline-block;
width: 20px; /* Marker image width */
height: 20px; /* Marker image height */
background-image: url('bullet.png'); /* Path to the marker image */
background-size: contain; /* Fit the image to the marker box */
margin-right: 10px; /* Space between the marker and item text */
}
</style>
</head>
<body>
<h1>List with image markers</h1>
<ul role="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</body>
</html>Try it yourself
Give an unordered list square markers and keep wrapped lines aligned with the rest of the text.
Show one solution
ul { list-style: square outside; }