HTML list elements and how they render

Lists are everywhere in markup yet rarely get a second thought. Four elements are in scope here: ordered lists <ol>, unordered lists <ul>, description lists <dl>, and interactive lists <menu>.

The first three of those hold list items (<li>): an <ol> numbers its items, while <ul> and <menu> show bullet markers. Those markers are styleable through the ::marker pseudo-element. Description lists work differently, pairing description terms (<dt>) with description details (<dd>) and producing no markers at all. They are intended for metadata and glossaries, though sightings in the wild are rare.

Resetting user agent styles

Browsers ship their own UA styles that give lists visual structure by default. Removing the markers is the familiar first step:

/* Zap all list markers! */
ol, ul, menu {
  list-style: none;
}

Modern CSS makes it possible to target only certain list instances. Combining :where() with :not() lets you strip markers from all lists while keeping them where they belong, such as inside long-form content like an article:

/* Where there are lists that are not articles where there are lists... */
:where(ol, ul, menu):not(article :where(ol, ul, menu)) {
  list-style: none;
}

The choice of :where() over :is() matters for specificity: :where() always carries zero specificity, while :is() adopts the specificity of its most specific selector. That makes :where() a gentler override that is easy to override in turn.

UA styles also pad list items to separate content from marker. Once markers are gone, that padding can go too:

:where(ol, ul, menu) {
  padding-left: 0; /* or padding-inline-start */
}

This blanket padding removal has a side effect: the lists kept inside <article> elements lose their spacing as well, leaving their markers hanging off the edge of the content box. Note that UA styles give <menu> an extra 40px of padding. The list-style-position property can stop markers from hanging outside their container — or perhaps hanging markers are simply a matter of stylistic preference.

Accessibility pitfalls

Markers and semantics in Safari

Applying list-style: none; introduces a real problem: Safari does not expose ordered and unordered lists styled that way as actual lists when content is navigated with a screen reader. Removing the markers ends up removing the semantics too. The remedy is to add an ARIA list role to the list and a listitem role to each item, so screen readers pick them up again:

<ol style="list-style: none;" role="list">
  <li role="listItem">...</li>
  <li role="listItem">...</li>
  <li role="listItem">...</li>
</ol>

<ul style="list-style: none;" role="list">
  <li role="listItem">...</li>
  <li role="listItem">...</li>
  <li role="listItem">...</li>
</ul>

Safari treats this behavior as a feature, not a bug. Users had complained that screen readers announced too many lists, since developers tend to overuse them, so only lists carrying role="list" are announced now. Scott O’Hara documents the full history.

Giving lists context

A second concern is not something authors cause. The same reasoning that calls for an aria-label on heading-less <section> elements sometimes applies to a list with no heading that describes it.

<!-- This list is somewhat described by the heading -->
<section>
  <h2>Grocery list</h2>
  <ol role="list">
     <!-- ... -->
  </ol>
</section>

<!-- This list is described by the aria-label -->
<ol role="list" aria-label="Grocery list">
  <!-- ... -->
</ol>

Neither approach is mandatory: a heading or an ARIA label only adds context. Test with screen readers and pick what gives the best experience for the situation. On the subject of aria-label, Eric Bailey makes the case that it is a code smell.

The <menu> element

Menus are unordered lists meant for interactive items, and they are exposed to the accessibility tree as unordered lists. Early versions of the HTML spec led to misconceptions — that menus were like <nav> elements, or meant for context menus and toolbars. MDN covers the deprecated menu-related material in detail. The semantic pattern today looks like this:

<menu aria-label="Share article">
  <li><button>Email</button></li>
  <li><button>Twitter</button></li>
  <li><button>Facebook</button></li>
</menu>

Good use cases exist. The example above wraps a set of social sharing buttons in a labeled <menu>, where the “Share article” label supplies meaningful context about what the buttons do. Menus are not required, and they are not HTML landmarks. They are available for anyone who prefers fewer <div>s and wants an aria-label to add context to a component.

Description lists and other uses

Description lists are the remaining element, and MDN does not consider them lists in the same sense — they are groups of terms and details. Their intended role is metadata, glossaries, and other key-value pairs. One reason to steer clear: every screen reader announces them differently.

On a brighter note, lists support plenty beyond plain content, including building a table of contents, visualizing a timeline of events, converting a list into a horizontal comma-separated list, and styling the marker.