Lesson 23 of 51 · Module 4, lesson 2 of 6 · 3 min

Numbered lists

Make numbered lists for steps and rankings, and change how they count.

What you'll learn

  • How to make a numbered list with <ol>
  • How to start at another number, count down, or use letters
  • When a list should be numbered

Why this matters

In a recipe, step 3 must come after step 2. When the order matters, a numbered list says so — to readers and to screen readers, which announce "list, 5 items" and read each number.

A numbered list

<ol> means ordered list. The items are <li>, as before. The browser adds the numbers for you.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tomato soup steps</title>
</head>
<body>
  <h1>How to make tomato soup</h1>
  <ol>
    <li>Cut the tomatoes and the onion.</li>
    <li>Cook them in water for twenty minutes.</li>
    <li>Blend the soup.</li>
    <li>Add salt to taste.</li>
  </ol>
</body>
</html>

What you'll see: the steps numbered 1 to 4.

The page "How to make tomato soup" with four numbered steps, 1 to 4.

Add a step in the middle, and the numbers after it change by themselves. That is the big advantage over typing numbers.

Changing the numbers

AttributeWhat it doesExample
startStart at another number<ol start="5"> counts 5, 6, 7…
reversedCount down (a boolean attribute)<ol reversed> counts 4, 3, 2, 1
typeLetters or Roman numeralstype="A", type="a", type="I", type="i"
html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Top dishes</title>
</head>
<body>
  <h2>My top three dishes</h2>
  <ol reversed>
    <li>Fresh bread</li>
    <li>Green salad</li>
    <li>Tomato soup</li>
  </ol>
  <h2>Choose one answer</h2>
  <ol type="A">
    <li>Twenty minutes</li>
    <li>One hour</li>
  </ol>
</body>
</html>

Two lists. "My top three dishes" counts down 3, 2, 1: Fresh bread, Green salad, Tomato soup. "Choose one answer" uses letters A and B.

Use type when the letters or numerals are part of the meaning — for example, answers A, B, C that a question refers to. If you only want a different look, that is a job for CSS.

Numbered lists inside lists

As with bulleted lists, an inner list goes inside an <li>. You can mix kinds: a numbered list of steps can hold a bulleted list of items.

Try it yourself

  1. Select the steps example and choose Try it.
  2. Add a new step between steps 1 and 2. Watch the numbers update.
  3. Add start="10", then change it to reversed.

Common mistakes

  • Typing the numbers yourself, as in <li>1. Cut the tomatoes</li>. You get "1. 1. Cut…". Fix: let <ol> number the items.
  • Using <ol> when the order does not matter. The numbers suggest an order that is not there. Fix: use <ul>.
  • Putting start or type on an <li>. They belong on the <ol>. Fix: move them.

Check yourself

  1. Which element makes a numbered list?
  2. How do you make a list start at 3?
  3. You add a step in the middle of an <ol>. What happens to the numbers?

Answers

  1. <ol>.
  2. <ol start="3">.
  3. They update by themselves.

Next: the last kind of list pairs words with their explanations — like a glossary.

Chat with us on WhatsApp