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?

A list gathers related items. It helps a reader see where each item begins. Browsers and reading tools can also recognise the items as a group. A set of paragraphs with typed bullet characters may look similar, but it does not describe that same structure.

Think of preparing for a college workshop. A notebook, a pen and a water bottle are supplies; the order in which you pack them is not important. Opening a file, editing it and saving it are steps; their order matters.

Choose ul or ol

ElementMeaningFamiliar use
ulAn unordered list; changing the item order does not change the essential meaningSupplies to bring
olAn ordered list; the sequence mattersInstructions to follow
liOne item in either kind of listOne supply or one step

The letters ul stand for unordered list. Ol stands for ordered list. Li stands for list item. The element names stay in English even when the list content uses another language.

HTML fragment — part of a document
<ul>
  <li>Notebook</li>
  <li>Pen</li>
</ul>

<ol>
  <li>Open the saved page.</li>
  <li>Check the heading.</li>
</ol>

The opening list tag creates the group. Each li starts one item. Close that item before starting its next sibling. For clear beginner examples, write every closing li tag even though HTML permits omission in certain positions.

Complete program: packing-list.html

Save this file and open it in a browser. The first list should show bullets. The second should show numbered steps under the browser's usual styles.

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>
Browser previewDocument title: Workshop Packing and Setup

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.

Expected result: three supplies form one group, followed by three numbered actions. The exact bullet shape and spacing can vary with browser styles. HTML describes the relationship; CSS can change its appearance later.

Continue, count backwards or change a number

The start attribute gives an ol its starting number. Its value is an integer: a whole number, such as 4. It does not accept a word such as four.

HTML fragment — part of a document
<ol start="4">
  <li>Save your changes.</li>
  <li>Reload the page.</li>
</ol>

The items normally display as 4 and 5. This can continue instructions after an explanation between two lists.

The reversed attribute makes an ordered list count down. It is a boolean attribute: its presence turns the feature on. Writing reversed="false" still turns it on. Without start, a reversed list normally begins at the number of its items.

The value attribute on an li inside an ol sets that item's ordinal number. Following items continue from that value in the list's direction. Use it when the numbering really needs a jump, rather than typing a number into the item text.

HTML fragment — part of a document
<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>

Ol also supports type values 1, a, A, i and I for decimal numbers, letters and Roman numerals. Start still uses an integer: type="A" start="3" begins with C. For ordinary visual styling, prefer CSS later. The old type attribute on ul is obsolete; do not use it to choose bullet shapes.

A list inside a list item

A nested list is a smaller list that belongs to an item in a larger list. Think of a bag checklist: the item stationery can contain the smaller items pen and notebook.

Put the inner ul or ol inside the relevant li, before that li closes. Do not place it as a direct sibling of li inside the outer list.

Let each smaller list have an owner
  1. 1Choose ul or ol by meaning
  2. 2Open the parent li
  3. 3Put the smaller list inside it
  4. 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

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>
Browser previewDocument title: Practice Folder Checklist

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.

The two file names belong to HTML files. Personal notes is a separate outer item. The numbered list begins at 4 and continues to 5. Inspect those relationships in the source as well as the browser.

What can an item contain?

An li can contain text, links, paragraphs and another list when that content belongs to the item. Keep the wording short where possible. A long item can use paragraphs instead of repeated br tags. A heading introducing the whole list belongs before ul or ol, rather than directly between its items.

Problem and solution: the smaller list has no owner

Problem: a student closes the stationery li and then puts a second ul directly inside the outer ul. It appears indented, so they assume it is correct.

Solution: move the smaller ul before the closing tag of the stationery li. Visual indentation is not proof of the intended relationship. Ask, “Which item does this smaller list explain?” and place it inside that item.

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

  1. Choose a list for supplies and a list for assembly instructions. Explain each choice.
  2. What does li represent?
  3. What numbers appear in a two-item ol with start="4"?
  4. Where should a nested list sit relative to its parent li?
  5. Why does reversed="false" still reverse a list?
  6. 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
  1. Use ul for supplies whose order is not important, and ol for assembly steps whose sequence matters.
  2. One list item inside ul or ol.
  3. Normally 4 and 5.
  4. Inside the parent li, before that parent's closing tag.
  5. Reversed is boolean. Its presence activates it regardless of that written value.
  6. 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?

Ol represents a list where sequence matters. Ul represents a group where changing the order does not change its essential meaning. Default numbering and bullets are visual clues to these meanings.

How do start and value differ?

Start sets the first ordinal number of an ol. Value sets the ordinal number of a particular li within an ol, affecting the following sequence too.

Can lists be nested at different levels?

Yes. Put each smaller list inside the li it explains. Keep the depth useful; too many levels can make the content difficult to follow.

Should headings be direct children of ul?

No. Place a heading for the whole list before the list. Items are represented by li; content describing an individual item belongs inside that li.

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.