CHAPTER 14 · HTML
Lists: group items, show steps and build nested lists
A shopping note groups things to bring. A recipe puts actions in order. HTML has different lists for these two jobs. Learn to choose a list by its meaning, then put smaller lists inside it when an item needs more detail.
Download example files (ZIP)Why use a list?
Choose ul or ol
<ul>
<li>Notebook</li>
<li>Pen</li>
</ul>
<ol>
<li>Open the saved page.</li>
<li>Check the heading.</li>
</ol>Complete program: packing-list.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Workshop Packing and Setup</title>
</head>
<body>
<h1>Prepare for the page workshop</h1>
<h2>Bring these supplies</h2>
<ul>
<li>A notebook</li>
<li>A pen</li>
<li>A water bottle</li>
</ul>
<h2>Follow these setup steps</h2>
<ol>
<li>Open your practice folder.</li>
<li>Open the saved HTML file.</li>
<li>Read the heading in the browser.</li>
</ol>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Continue, count backwards or change a number
<ol start="4">
<li>Save your changes.</li>
<li>Reload the page.</li>
</ol><ol reversed start="3">
<li>Check the last example.</li>
<li>Check the middle example.</li>
<li>Check the first example.</li>
</ol>
<ol>
<li>Read the notice.</li>
<li value="5">Continue at task five.</li>
<li>Finish task six.</li>
</ol>A list inside a list item
- 1Choose ul or ol by meaning
- 2Open the parent li
- 3Put the smaller list inside it
- 4Close the parent li after the smaller list
Indentation alone does not establish ownership. The nesting of elements does.
Complete program: nested-practice-list.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Practice Folder Checklist</title>
</head>
<body>
<h1>Check your practice folder</h1>
<ul>
<li>HTML files
<ul>
<li>First notice</li>
<li>Updated notice</li>
</ul>
</li>
<li>Personal notes</li>
</ul>
<h2>Finish the final two tasks</h2>
<ol start="4">
<li>Save the latest file.</li>
<li>Explain your changes to a partner.</li>
</ol>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
What can an item contain?
Problem and solution: the smaller list has no owner
Common mistakes and useful tips
Typing 1, 2 and 3 into paragraphs instead of using ol. Choosing ol simply because numbered items look attractive when order has no meaning. Putting ordinary paragraphs directly inside ul instead of inside li. Closing the parent li before its nested list. Using start on ul, or expecting value on an unordered item to create numbering. Writing reversed="false" to switch reversal off: remove the attribute instead. Using lists to create a whole visual page layout. Learn CSS for layout later.
Practice questions
Choose a list for supplies and a list for assembly instructions. Explain each choice. What does li represent? What numbers appear in a two-item ol with start="4"? Where should a nested list sit relative to its parent li? Why does reversed="false" still reverse a list? Build a workshop page with three supplies, four ordered steps and a nested list of two stationery items. Explain which item owns the nested list.
Check your practice answers
Use ul for supplies whose order is not important, and ol for assembly steps whose sequence matters. One list item inside ul or ol. Normally 4 and 5. Inside the parent li, before that parent's closing tag. Reversed is boolean. Its presence activates it regardless of that written value. Use a complete document. Put the two stationery items in an inner ul inside the stationery li. Keep the four actions in a separate ol and check their order in the browser.
Interview questions
What is the difference between ordered and unordered lists?
How do start and value differ?
Can lists be nested at different levels?
Should headings be direct children of ul?
Quick revision
Ul groups items; ol orders them; li holds each item. Start, reversed and li value control ordered numbering. A smaller list belongs inside its parent item. Write clear text and closing tags before changing the styling.