Reviewing lists
All three list types have the same role
In the HTML Accessibility API Mappings spec, <ul>, <ol> and <dl> all map to the list role:
The type of list changes the markers and the presentation, not the role.
What does differ is the elements inside the list, which each have their own role:
Type 1: Unordered list
The <ul> element represents an unordered list of items, typically rendered as a bulleted list.
- Flowers
- Trees
- Birds
- Bees
HTML markup
<ul>
<li>Flowers</li>
<li>Trees</li>
<li>Birds</li>
<li>Bees</li>
</ul>
Type 2: Ordered list
The <ol> element represents an ordered list of items. Ordered lists are typically rendered as a numbered list.
- Make the bed
- Clean the bathroom
- Wash the dishes
- Hang the washing
HTML markup
<ol>
<li>Make the bed</li>
<li>Clean the bathroom</li>
<li>Wash the dishes</li>
<li>Hang the washing</li>
</ol>
Changing the numbering with value
The value attribute on an <li> inside an <ol> sets the number of that item. In this example every item has a value, so the numbers show a tie for second place. An item without a value carries on counting from the item before it.
- Rabbit
- Fox
- Frog
- Snake
HTML markup
<ol>
<li value="1">Rabbit</li>
<li value="2">Fox</li>
<li value="2">Frog</li>
<li value="4">Snake</li>
</ol>
Starting the numbering with start
The start attribute on an <ol> sets the number of the first item. The following items count on from there.
- Fifth item
- Sixth item
- Seventh item
HTML markup
<ol start="5">
<li>Fifth item</li>
<li>Sixth item</li>
<li>Seventh item</li>
</ol>
Counting down with reversed
The reversed attribute on an <ol> makes the numbers count down. The first item gets the highest number.
- Third place
- Second place
- First place
HTML markup
<ol reversed>
<li>Third place</li>
<li>Second place</li>
<li>First place</li>
</ol>
Changing the number style with type
The type attribute on an <ol> sets the style of the numbers: 1 (decimal, the default), a and A (letters), and i and I (Roman numerals). Only the marker changes. It is still an ordered list with the same role.
type="1"
- Make the bed
- Clean the bathroom
- Wash the dishes
type="a"
- Make the bed
- Clean the bathroom
- Wash the dishes
type="A"
- Make the bed
- Clean the bathroom
- Wash the dishes
type="i"
- Make the bed
- Clean the bathroom
- Wash the dishes
type="I"
- Make the bed
- Clean the bathroom
- Wash the dishes
HTML markup
<p><code>type="1"</code></p>
<ol type="1">
<li>Make the bed</li>
<li>Clean the bathroom</li>
<li>Wash the dishes</li>
</ol>
<p><code>type="a"</code></p>
<ol type="a">
<li>Make the bed</li>
<li>Clean the bathroom</li>
<li>Wash the dishes</li>
</ol>
<p><code>type="A"</code></p>
<ol type="A">
<li>Make the bed</li>
<li>Clean the bathroom</li>
<li>Wash the dishes</li>
</ol>
<p><code>type="i"</code></p>
<ol type="i">
<li>Make the bed</li>
<li>Clean the bathroom</li>
<li>Wash the dishes</li>
</ol>
<p><code>type="I"</code></p>
<ol type="I">
<li>Make the bed</li>
<li>Clean the bathroom</li>
<li>Wash the dishes</li>
</ol>
Combining type, start and reversed
The attributes work together. This first list uses Roman numerals starting at 4. The second counts down in capital letters, so the first item gets the highest letter.
- Fourth item
- Fifth item
- Sixth item
- Third place
- Second place
- First place
HTML markup
<ol type="i" start="4">
<li>Fourth item</li>
<li>Fifth item</li>
<li>Sixth item</li>
</ol>
<ol type="A" reversed>
<li>Third place</li>
<li>Second place</li>
<li>First place</li>
</ol>
Changing the marker with CSS list-style-type
CSS can set the marker too, with a wider range of values than the type attribute. Ordered lists can use upper-roman, lower-greek, decimal-leading-zero and many more. Unordered lists can use disc, circle and square. The markup stays a plain <ol> or <ul>.
- Rabbits
- Foxes
- Birds
- Rabbits
- Foxes
- Birds
- Rabbits
- Foxes
- Birds
- Rabbits
- Foxes
- Birds
- Rabbits
- Foxes
- Birds
HTML markup
<ol class="roman">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ol>
<ol class="greek">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ol>
<ol class="zero">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ol>
<ul class="circle">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
<ul class="square">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
CSS
.roman { list-style-type: upper-roman; }
.greek { list-style-type: lower-greek; }
.zero { list-style-type: decimal-leading-zero; }
.circle { list-style-type: circle; }
.square { list-style-type: square; }
CSS wins over the type attribute
If a list has both, the CSS list-style-type is used and the type attribute is ignored. This list has type="A" but shows Roman numerals.
- Rabbits
- Foxes
- Birds
HTML markup
<ol type="A" class="roman">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ol>
CSS
.roman { list-style-type: upper-roman; }
Custom marker text with a string
list-style-type also accepts a string, so the marker can be any text or symbol. The string is generated by the browser and is not part of the list item's content.
- Rabbits
- Foxes
- Birds
HTML markup
<ul class="arrow">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
CSS
.arrow { list-style-type: "\2192 "; }
Styling markers with ::marker
The ::marker pseudo-element styles the marker without changing the list item's text. Only a small set of properties works on it, including color, font-size, font-weight and content. Properties such as background or margin do nothing.
- Rabbits
- Foxes
- Birds
- Rabbits
- Foxes
- Birds
HTML markup
<ol class="marker-style">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ol>
<ul class="marker-content">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
CSS
.marker-style li::marker {
color: light-dark(#b00020, #ff8a9a);
font-weight: bold;
font-size: 1.25em;
}
.marker-content li::marker {
content: "\2605 ";
}
Marker position with list-style-position
By default the marker sits outside the list item's box (outside), so wrapped lines line up under the text. With inside, the marker is part of the text flow and wrapped lines go back under the marker. The outline on each item shows the difference.
- Rabbits are small mammals that live in burrows and eat grass.
- Foxes are wild dogs with bushy tails.
- Rabbits are small mammals that live in burrows and eat grass.
- Foxes are wild dogs with bushy tails.
HTML markup
<ul class="outside">
<li>Rabbits are small mammals that live in burrows and eat grass.</li>
<li>Foxes are wild dogs with bushy tails.</li>
</ul>
<ul class="inside">
<li>Rabbits are small mammals that live in burrows and eat grass.</li>
<li>Foxes are wild dogs with bushy tails.</li>
</ul>
CSS
.outside { list-style-position: outside; }
.inside { list-style-position: inside; }
Image markers with list-style-image
An image can replace the marker. Provide a fallback list-style-type in case the image does not load. The image is decorative and has no text alternative, so it should not carry any meaning.
- Rabbits
- Foxes
- Birds
HTML markup
<ul class="image-marker">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
CSS
.image-marker {
list-style-image: url("data:image/svg+xml,...");
list-style-type: disc;
}
Nested numbering with CSS counters
A nested ordered list normally restarts at 1 for each child list. CSS counters can join the levels, so the children are numbered 1.1, 1.2 and so on.
Generated numbers are not text
Numbers made with CSS counters are generated content. They are not in the page's text, so they cannot be selected or searched, and support for announcing them varies. These lists have list-style: none, so they also need role="list" for Safari with VoiceOver. Use native numbering unless you need nested numbers like 1.1.
- Animals
- Rabbits
- Foxes
- Plants
- Flowers
- Trees
HTML markup
<ol class="counter-list" role="list">
<li>Animals
<ol role="list">
<li>Rabbits</li>
<li>Foxes</li>
</ol>
</li>
<li>Plants
<ol role="list">
<li>Flowers</li>
<li>Trees</li>
</ol>
</li>
</ol>
CSS
.counter-list,
.counter-list ol {
list-style: none;
counter-reset: item;
padding-left: 0;
}
.counter-list li {
counter-increment: item;
}
.counter-list li::before {
content: counters(item, ".") ". ";
}
.counter-list ol { margin-left: 1.5em; }
Type 3: Description list
The <dl> element represents a description list. The element encloses a list of groups of terms (specified using the <dt> element) and descriptions (provided by <dd> elements).
- Frog
- Wet green thing
- Rabbit
- Warm fluffy thing
- Snake
- Cold dry thing
HTML markup
<dl>
<dt>Frog</dt>
<dd>Wet green thing</dd>
<dt>Rabbit</dt>
<dd>Warm fluffy thing</dd>
<dt>Snake</dt>
<dd>Cold dry thing</dd>
</dl>
A description list with more than one description or term
A term can have several descriptions, and several terms can share one description. The structure is still a single list.
- Rabbit
- Warm fluffy thing
- Lives in a burrow
- Frog
- Toad
- Cold damp thing
HTML markup
<dl>
<dt>Rabbit</dt>
<dd>Warm fluffy thing</dd>
<dd>Lives in a burrow</dd>
<dt>Frog</dt>
<dt>Toad</dt>
<dd>Cold damp thing</dd>
</dl>
A description list with <div> groups
Each term and its descriptions can be wrapped in a <div>. This is valid HTML and makes the groups easy to style, and the elements inside still map to the same roles.
- Frog
- Wet green thing
- Rabbit
- Warm fluffy thing
- Snake
- Cold dry thing
HTML markup
<dl>
<div>
<dt>Frog</dt>
<dd>Wet green thing</dd>
</div>
<div>
<dt>Rabbit</dt>
<dd>Warm fluffy thing</dd>
</div>
<div>
<dt>Snake</dt>
<dd>Cold dry thing</dd>
</div>
</dl>
Using role="list"
Lists and list items can also be created using list and listitem roles. Native <ul>, <ol> and <li> elements are preferred, so use these roles only when you cannot use the native elements, or to restore list semantics (see the next example).
HTML markup
<div role="list">
<div role="listitem">Item one</div>
<div role="listitem">Item two</div>
<div role="listitem">Item three</div>
</div>
A styled unordered list
This list has had its bullets removed with list-style: none. The <ul> and <li> elements are still there, but the markup has no role.
VoiceOver and lists with no bullets
If you remove the bullets from a list using list-style: none, Safari with VoiceOver may no longer recognise it as a list. It won’t announce that it’s a list or how many items it contains, even though the <ul> and <li> elements are still present. Other browser and screen reader combinations are not affected.
To keep the list semantics, you need to add role="list" to the <ul>. See the next example.
- Rabbits
- Foxes
- Birds
HTML markup
<ul class="styled-list">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
CSS
.styled-list {
list-style: none;
margin-left: 0;
padding: .5em 0;
}
A styled unordered list with role="list"
The same list with the bullets removed, but with role="list" added to the <ul>. The <li> elements need no role, because they are still list items. Safari with VoiceOver now recognises it as a list.
- Rabbits
- Foxes
- Birds
HTML markup
<ul class="styled-list" role="list">
<li>Rabbits</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
A nested unordered list
- Rabbits
- Holland Lop
- European rabbit
- Rex rabbit
- Pygmy rabbit
- Foxes
- Birds
HTML markup
<ul>
<li>Rabbits
<ul>
<li>Holland Lop</li>
<li>European rabbit</li>
<li>Rex rabbit</li>
<li>Pygmy rabbit</li>
</ul>
</li>
<li>Foxes</li>
<li>Birds</li>
</ul>
A fake list
This is a fake list. The numbers are typed as text inside <div> elements, so assistive technology does not announce a list or how many items it has.
HTML markup
<div>1. Flowers</div>
<div>2. Trees</div>
<div>3. Birds</div>
<div>4. Bees</div>