Lists and Description Lists
When to use ul, ol and dl, how list markup shows up in the accessibility tree, and the nesting mistakes the parser does not repair for you.
Lists and Description Lists
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Use `<ul>` when order doesn't matter, `<ol>` when it does, and `<dl>` for term and description pairs. Each `<ul>` and `<ol>` holds `<li>` children.
- Lists are real structure. In a test the accessibility tree exposed `list` and `listitem` roles, letting a screen reader announce how many items there are.
- Only `<li>` may be a direct child of `<ul>` or `<ol>`. In a test, a `<div>` placed directly inside a `<ul>` was left in place, and the tree counted only the `<li>` as a list item.
- `<ol>` takes `start`, `reversed` and a per-item `value`. They change the numbers, not the order of the items in the source.
- A `<dl>` holds `<dt>` terms and `<dd>` descriptions, and several terms can share a description or one term can have several. A `<div>` may wrap each group for styling.
Why lists get their own elements
Imagine three paragraphs that each start with a bullet character you typed by hand. They look like a list, but to the browser they’re three unrelated paragraphs. It can’t tell a screen reader “list of three items”, can’t let you style the group as a unit, and can’t number them for you.
HTML’s list elements fix that by putting the relationship in the markup. There are three kinds, and the choice is about meaning.
Unordered, ordered and description lists
<ul>
<li>Eggs</li>
<li>Flour</li>
</ul>
<ol>
<li>Preheat the oven</li>
<li>Mix</li>
<li>Bake</li>
</ol>
<dl>
<dt>HTML</dt>
<dd>The language of page structure.</dd>
<dt>CSS</dt>
<dd>The language of presentation.</dd>
</dl>
<ul>(unordered): the order doesn’t change the meaning. A shopping list, a set of navigation links, a row of tags.<ol>(ordered): the order matters. Steps, rankings, a table of contents.<dl>(description list): name and value pairs.<dt>is the term,<dd>the description. Glossaries are the textbook case, but so is any “label: value” group, such as a recipe’s metadata or a product’s specs.
A quick test for choosing between ul and ol: if you reordered the items, would the content mean something different? If yes, ol.
What the browser and assistive tech see
In a test with headless Chromium 159, the accessibility tree exposed <ul> and <ol> as list with listitem children, and <dl> as term and definition entries. That’s what lets a screen reader say “list, three items”. Bullets and numbers are only the default presentation. You can remove them with list-style: none and, in Chromium, the list role stayed: a <ul style="list-style:none"> was still reported as a list with two listitems. Some browser and screen reader combinations have a history of dropping list semantics when the markers are removed, notably Safari with VoiceOver, so a navigation list often gets an explicit role="list". I could not test Safari here, so check the combinations you support.
Nesting rules
Only <li> elements may be direct children of <ul> and <ol>. To nest a list, put it inside an <li>:
<ul>
<li>Fruit
<ul><li>Apple</li><li>Pear</li></ul>
</li>
</ul>
The parser does not fix the common mistake of putting something else straight inside the list. In a test, <ul><div>wrapped</div><li>x</li></ul> came out unchanged, and the accessibility tree listed the div’s text as plain content with only one list item. It’s invalid HTML that happens to render, which is the dangerous kind. Wrap the content in an <li> instead.
In a <dl>, a single <dt> can have several <dd>s and a single <dd> can describe several <dt>s. Wrapping each group in a <div> is allowed and useful for styling or for repeating groups. In a test, a dl made of two div groups, the second with two terms and two definitions, was exposed as three term and three definition entries in the order written.
Controlling the numbers
An <ol> has three attributes that change numbering without changing the markup’s order: start (the first number), reversed (count down), and value on an individual <li> (set that item’s number, and later items continue from it). MDN’s compatibility data lists all three as supported in every current browser, but I could not read the rendered numbers in my test setup, so I won’t claim a measured result. Try it in DevTools. The point is that the list’s content order stays the same, so a reversed countdown is still stored first-to-last.
What the video covers
The embed is Dave Gray’s “HTML Lists Tutorial | HTML5 List Types: Ordered, Unordered & Description” (December 2021, about 11 minutes). Its chapters are the three types of HTML lists (0:25), the dev environment overview (0:40), ordered lists (2:04), unordered lists (4:32), description lists (6:48) and validating your HTML (8:58). It is the only candidate I found that covers description lists as well as the two common ones. I could not read a transcript, so I describe it only from the chapters. The accessibility checks and the nesting tests above are this lesson’s own. Kevin Powell’s shorter lists video, linked below, covers only ol and ul.
Where this fits
This follows headings, paragraphs and text semantics as the second everyday text structure. Navigation menus are lists of links, the next lesson, and the landmarks lesson shows where such a list lives on a page.
Check yourself
A navigation menu is a set of links in no required order. Which list element fits, and why not a series of `div`s?
A `<ul>` with `<li>` per link. The list tells assistive technology it is a group and how many items it has, which a stack of `div`s does not. The bullets can be removed with CSS.
You write `<ul><div>One</div><li>Two</li></ul>`. What does the browser do with the `div`?
It leaves it in place. The parser does not repair this, and the markup is invalid. In a test the accessibility tree listed only the `<li>` as a list item, with 'One' as plain text. Keep `<li>` as the only direct children.
How do you write a countdown list starting at 5, and does the markup order change?
Use `<ol reversed start="5">`. The items stay in the same order in the source and the DOM. Only the displayed numbers count down. `start` sets the first number and `reversed` flips the direction.
What is a description list for, and how is it different from a list of paragraphs?
It pairs terms with descriptions: glossary entries, metadata like 'Author: Jo', FAQ-style pairs. `dt` and `dd` are exposed as `term` and `definition`, so the relationship is in the markup rather than in your styling.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.