Skip to content
Tutorials Center
My learning

Topics

Lesson 86 of 139 ยท Lists, Tables and Forms

Styling Lists

Style HTML lists with CSS. Change bullets and numbers with list-style, color them with ::marker, build custom markers, and remove bullets without hurting accessibility.

Lists are everywhere on the web. Navigation menus, feature checklists, recipe steps, search results and comment threads are all lists underneath. HTML gives them structure (you met <ul>, <ol> and <li> in Lists), and CSS decides how they look: which bullet appears, what color the numbers are, how far the text is indented, or whether there is any visible marker at all.

In this lesson you will learn the list-style properties, the ::marker pseudo-element, a few ways to build fully custom bullets, and how to strip the bullets off a navigation list without making it invisible to screen readers.

What makes something a list item

A list item is any element with display: list-item. Browsers give <li> that value by default, and it does two things: the element behaves like a block, and it gets a marker box in front of it. The marker is the bullet or number you see.

The default spacing comes from the list itself, not the items. Browsers give <ul> and <ol> about 40px of padding-inline-start (left padding in left-to-right languages), plus a top and bottom margin. The markers sit inside that padding. If you set padding: 0 on a list and the bullets seem to vanish off the left edge, that is why: they are still there, hanging outside the box.

Choosing the marker: list-style-type

list-style-type picks the kind of marker. Unordered lists default to disc, and nested levels switch to circle and then square. Ordered lists default to decimal.

There are many built-in counter styles. The common ones:

  • Bullets: disc, circle, square, disclosure-closed, disclosure-open
  • Numbers: decimal, decimal-leading-zero
  • Letters and numerals: lower-alpha, upper-alpha, lower-roman, upper-roman
  • Other writing systems: lower-greek, armenian, georgian, hebrew, japanese-formal and more
  • none for no marker at all

You can also pass a string, which becomes the marker for every item, exactly as written:

CSS
.tasks {
  list-style-type: "โœ“ ";
}

Notice the space inside the quotes. A string marker is used as is, so you add the gap yourself.

Marker types side by side

Try swapping in disclosure-closed, upper-alpha or an emoji string such as "๐Ÿ‹ ".

Pick the element first, the marker second. If the order of the items matters, use <ol>, even if you then style it with letters. If it doesn't, use <ul>. The marker style is only decoration; the element carries the meaning. See Ordered Lists for start, reversed and value.

Marker position: list-style-position

By default markers are outside the item's content box: they hang in the list's padding, and wrapped lines of text line up neatly under the first word. With list-style-position: inside, the marker becomes part of the first line, so wrapped lines run back under the marker.

outside is almost always what you want for readable paragraphs. inside is useful when items have a background or border and you want the marker inside that box.

Image markers: list-style-image

list-style-image: url(...) replaces the marker with an image. It works, but you get no control over the image's size or alignment, so it has mostly been replaced by ::marker and pseudo-element techniques. If you use it, set a fallback list-style-type in case the image fails to load.

The list-style shorthand

list-style sets type, position and image in one declaration, in any order:

CSS
ul.compact { list-style: square inside; }
nav ul     { list-style: none; }

list-style: none is the line you will write most often. It removes the markers from menus, card grids and tag lists.

Styling the marker with ::marker

The ::marker pseudo-element selects the marker box itself. It is supported in all modern browsers, and it lets you style the bullet or number separately from the text:

CSS
li::marker {
  color: crimson;
  font-weight: bold;
}

Only a small set of properties work on ::marker: color, the font properties, white-space, content, animation and transition properties, and a few text properties such as direction and unicode-bidi. You cannot give it padding, margin or a background. If you need any of those, you need the custom-marker technique in the next section.

The content property on ::marker replaces the marker text, just like a string list-style-type. Combine it with :nth-child() or classes and you can give different items different markers.

Coloring and replacing markers

The status list still makes sense without color, because the words say "operational", "slow" and "outage". Never rely on marker color alone to carry meaning.

Fully custom markers with ::before

When you need a marker that ::marker can't produce, such as a circle with a background, an icon of a fixed size, or a marker positioned precisely, hide the real marker and draw your own with ::before:

  1. Remove the native marker with list-style: none.
  2. Give each li some left padding and position: relative.
  3. Add a ::before pseudo-element, position it in that padding, and style it however you like.
Badge-style custom bullets

The marker is drawn entirely with CSS: a green circle from ::before and a rotated L shape from ::after. Because it is positioned absolutely inside the padding, long items wrap cleanly beside it. The content: "" is empty, so screen readers have nothing extra to announce. You will learn more about pseudo-elements in Pseudo-elements and about rotation in 2D Transforms.

Removing bullets accessibly

Navigation bars, image galleries and tag clouds are lists with no visible markers. The usual reset is:

CSS
.menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

There is one subtle catch. Safari decided that a list with list-style: none might not be a "real" list, so with VoiceOver it stops announcing "list, 5 items". Most of the time that is fine. If the count matters to your users, for example in a list of search results, put the role back explicitly:

HTML
<ul class="results" role="list">
  ...
</ul>

role="list" on a <ul> is normally redundant, but here it restores the semantics. Many CSS resets use the selector ul[role="list"] to remove bullets only from lists that opted in, which keeps the two concerns tied together.

Don't fake lists with <div>s and line breaks. A real list tells assistive technology how many items there are and lets users jump between them. Keep the markup, and let CSS hide whatever you don't want to see.

Spacing and alignment tips

  • Control indentation with padding-inline-start on the list rather than margin on the items. It keeps markers aligned and works in right-to-left languages too.
  • Add space between items with margin-block on li, or turn the list into a flex or grid container and use gap.
  • For a horizontal menu, set display: flex on the <ul> (you will cover that in Flexbox Basics). Flex items are no longer list items, so their markers disappear anyway, but keep list-style: none for clarity.
  • Description lists (<dl>) have no markers at all. Style <dt> and <dd> directly; Description Lists shows the markup.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You set padding: 0 on a <ul> and the bullets disappear. Why?

    Markers default to list-style-position: outside. They live in the list's start padding, so removing it pushes them past the edge.
  2. 2. Which declaration gives every item in a list a "โ†’ " marker?

    A quoted string in list-style-type (or content on ::marker) is used as the marker exactly as written, including the trailing space.
  3. 3. You want a marker with a circular background and fixed size. What should you use?

    ::marker accepts only a few properties, such as color, font and content. Box properties like background and padding need a ::before pseudo-element.
  4. 4. Why might you add role="list" to a <ul> that has list-style: none?

    Safari stops reporting some unstyled lists as lists. An explicit role="list" restores the "list, N items" announcement.

Summary

  • <li> has display: list-item, which adds a marker box. Lists get default start padding that holds the markers.
  • list-style-type chooses the marker: keywords like square, upper-roman, or any quoted string.
  • list-style-position puts markers outside (default, neat wrapping) or inside the first line.
  • ::marker styles the marker's color, font and content, but not its box.
  • For fully custom markers, use list-style: none and draw with ::before.
  • When you remove bullets, consider role="list" so screen readers still announce the list.

Next: CSS Counters, where you will number anything, including nested sections like 1.2.3.