Unordered lists
Use <ul> for items where order does not matter. Each item is an <li>.
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>Ordered lists
Use <ol> when order matters, such as steps.
<ol>
<li>Open your editor</li>
<li>Write the code</li>
<li>Save and test</li>
</ol>You can change numbering with attributes: <ol type="A"> or <ol start="5">.
Nested lists
Place a list inside an <li>.
<ul>
<li>Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
<li>Backend</li>
</ul>Description lists
Use <dl> for terms and their meanings.
<dl>
<dt>HTML</dt>
<dd>Defines the structure of a page.</dd>
<dt>CSS</dt>
<dd>Defines the style of a page.</dd>
</dl>Lists for navigation
Menus on most websites are unordered lists of links styled with CSS. This is good for accessibility because screen readers announce the number of items.
Practice
Write an ordered list of steps to make tea, with a nested unordered list for the ingredients.
Practice tasks
Reading is not enough. Try these without copying code, then compare with the lesson.
- Make an unordered list of five hobbies and an ordered list of steps for making tea.
- Nest a list inside one item.
- Create a description list of three terms and definitions.
Common mistakes
- Placing text directly inside ul instead of li.
- Using lists only for layout rather than for related items.
Quick check
When should you use an ordered list?
When the sequence matters, such as steps.
Which element holds each item?
The li element.