Thuta Learning
HTML
IntermediateWeb DevelopmentBeginner

Ordered Lists

HTMLLesson 1820 min

What you'll walk away with

  • Choose between ol and ul by asking whether reordering changes the meaning
  • Predict the numbers produced by start, reversed and value on an li
  • Write sub-steps as a nested ol inside an li
  • Tell when numbering style belongs in CSS and when the type attribute is justified

Explain it simply

Explain it simply

Imagine reading instructions for instant noodles: boil water, add noodles, wait three minutes. Do these steps in a different order and you get a very different result. In HTML a list where order matters is an ol (ordered list), and the browser adds the numbers 1, 2, 3 for you.

Not typing the numbers yourself is the big win: insert a new step in the middle and every number after it updates automatically.

Problem → Why → Solution

The problem: numbers typed by hand

A setup guide has its numbers typed into the text. A week later an "Install the extension" step must go in second place, so every following number has to be edited by hand, and missing one produces two step 3s. Someone switches to ol but leaves the typed numbers in, and now the page shows "1. 1. Download" with doubled numbers.

setup.html
<p>1. Download VS Code</p>
<p>2. Create a project folder</p>
<p>3. Create index.html</p>

<!-- "fixed" version: the numbers now appear twice -->
<ol>
  <li>1. Download VS Code</li>
  <li>2. Create a project folder</li>
</ol>

Whose job is the number?

In an ol the number is not content: it is a marker the browser computes from each li's position. That is why the numbers stay correct whenever you add, delete or move an item. A screen reader can also announce "list, 3 items" and positions such as "1 of 3", which a typed "1." inside a paragraph cannot provide.

Core concept: the order is part of the meaning

Use ol when changing the order of the items would change their meaning: steps to perform, race results, a top-10 list, clauses of an agreement. As with ul, only li may be a direct child, and sub-steps go inside the parent li as a nested ol. A nested ol starts again from 1.

An li can hold much more than a short phrase. A real step often needs a sentence of explanation, a code snippet or a screenshot, and all of it belongs inside the same li so it stays attached to its number. Screen readers announce the item count when you enter a list and often each item's position, so a learner who is listening knows they are on step 4 of 7. Splitting one step across several li elements or loose paragraphs breaks both the numbering and that announcement.

AttributeOnWhat it does
start="4"olNumbers the first item 4
reversedolCounts down (3, 2, 1)
value="10"liMakes this item 10; the following ones continue 11, 12
type="a"olMarker kind (1, a, A, i, I)

Use these attributes only when the content's meaning calls for them. If a paragraph interrupts steps 1-3 and the list then continues, start="4" is correct; for a top-5 countdown, reversed is natural. They change the numbers in a meaningful way, and screen readers read those numbers out too.

The marker's look (colour, font, roman numerals or letters) is usually presentation, so use CSS list-style-type and ::marker. The spec does allow the type attribute, but recommends it only when the kind of marker carries meaning, such as a contract whose text says "see clause (b)", so the letters stay right even if the CSS fails to load.

Mental model: the browser does the counting
  1. Would reordering change meaning?
  2. Yes: ol, with each item in an li
  3. Browser numbers each li by position
  4. start/value move the counter

Never type the number into the li's text; counting is the browser's job.

General pattern

html
<ol start="N">           <!-- optional: begin at N; add reversed to count down -->
  <li>Step</li>
  <li>
    Step with sub-steps
    <ol>
      <li>Sub-step</li>
    </ol>
  </li>
  <li value="N">Step forced to number N</li>
</ol>

An ol is shaped like a ul; the difference is the optional attributes that control numbering. With none of them, numbering starts at 1 and goes up by one.

Example: steps to make your first web page

Do these three steps in reverse, opening a file in the browser before it exists, and nothing works, so ol is the right choice. Notice that the code contains no numbers at all.

html
<ol>
  <li>Create index.html</li>
  <li>Add page structure</li>
  <li>Open it in browser</li>
</ol>

Code breakdown

  1. Opening tag<ol>

    Starts the ordered list. With no attributes, numbering starts at 1 and the marker style is decimal (1. 2. 3.).

  2. First step<li>Create index.html</li>

    The text contains no "1.". The browser draws the "1." marker because this is the first li.

  3. Middle step<li>Add page structure</li>

    Insert a new step above this line and this item becomes 3 instead of 2 without any editing.

  4. Last step<li>Open it in browser</li>

    The third li gets "3.". A screen reader can announce its position, such as "3 of 3".

You should see
A numbered list appears:
1. Create index.html
2. Add page structure
3. Open it in browser
The numbers are drawn by the browser, and the list is indented about 40px.

Interrupted lists and countdowns

Tutorials often need a screenshot or an explanatory paragraph after a few steps. A new ol would restart at 1, so start tells it to continue. For a countdown, reversed starts from the number of items and counts down.

continue.html
<ol>
  <li>Install Node.js</li>
  <li>Open a terminal</li>
</ol>
<p>Check that node --version prints a version number before going on.</p>
<ol start="3">
  <li>Run npm init</li>
</ol>

<h2>Top 3 browsers in our survey</h2>
<ol reversed>
  <li>Firefox</li>
  <li>Safari</li>
  <li>Chrome</li>
</ol>

Result

The first list shows 1 and 2, and after the paragraph "Run npm init" is 3. In the countdown, Firefox is 3, Safari 2 and Chrome 1. If the paragraph only explains step 2, a simpler option is to move it inside step 2's li; then one ol is enough and no start attribute has to be kept in sync when steps are added.

In real projects

Where this shows up in real projects

Install guides on documentation sites, recipes, the "1 Cart → 2 Shipping → 3 Payment" progress indicator in a checkout, breadcrumbs and ranked search results all fit ol. In a breadcrumb the order Home → Courses → HTML tells you where the page sits, which is why most design systems mark breadcrumbs up as an ol.

Designs often put the number in a circle or show it large and coloured. Developers keep the ol, hide the default marker with list-style: none, and draw their own with CSS counters (counter-reset, counter-increment) or ::marker. The look changes, while the HTML meaning and item count stay the same for screen readers.

Markdown produces ol too: in CommonMark, lines starting with "1.", "2." become an ol, and a list whose first item is "4." is rendered with start="4". So the same rules apply to README files and blog posts written in Markdown.

Common mistakes

Common mistakes

1. Typing the number inside the li

<li>1. Preheat the oven</li> combines with the browser's marker to show "1. 1. Preheat the oven", and the typed number goes wrong as soon as items move. Delete the number from the text and let the browser count.

2. Using ol for a list with no real order

Writing a feature list as an ol because numbers look nice implies a meaning that is not there: is this step 1, or the most important? If you only want the look, show a ul with CSS list-style-type: decimal.

3. Restarting at 1 after an interruption

When a paragraph splits a list, the second ol restarts at 1 and users see two step 1s. Add start to the second ol, or move the paragraph inside the previous step's li.

Best practices

Best practices

  • Start each step with a verb and keep one action per step (Open, Click, Save).
  • If a step has a visible result ("A window opens"), say so inside that same li.
  • When sub-steps pile up, use a nested ol and style it a, b, c with CSS.

Mini challenge

Mini challenge: an install guide with a break

Write an install guide for a code editor. Step 2 has two sub-steps, and after step 3 a warning paragraph interrupts the list, which then continues from 4.

  • The first ol has three steps, with no numbers typed in the li text
  • Step 2's li holds a nested ol of two sub-steps, styled a, b with CSS
  • A p sits between the two ol elements
  • The second ol starts at 4 and has two steps
install.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Install the editor</title>
  <!-- TODO: CSS that turns nested ol markers into a, b -->
</head>
<body>
  <h1>Install the editor</h1>
  <!-- TODO: ol with 3 steps; step 2 contains a nested ol -->
  <!-- TODO: warning paragraph -->
  <!-- TODO: second ol that continues the numbering -->
</body>
</html>

Expected: 1. Download the installer / 2. Run the installer (a. Accept the licence, b. Choose a folder) / 3. Open the editor, then the warning paragraph, then 4. Install the HTML extension / 5. Restart the editor.

Show hint

The selector ol ol { list-style-type: lower-alpha; } targets only an ol inside another ol. For the second list put start="4" on the ol, not on an li.

Show solution
install.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Install the editor</title>
  <style>
    ol ol { list-style-type: lower-alpha; }
  </style>
</head>
<body>
  <h1>Install the editor</h1>
  <ol>
    <li>Download the installer</li>
    <li>Run the installer
      <ol>
        <li>Accept the licence</li>
        <li>Choose a folder</li>
      </ol>
    </li>
    <li>Open the editor</li>
  </ol>
  <p><strong>Warning:</strong> close other editors before the next step.</p>
  <ol start="4">
    <li>Install the HTML extension</li>
    <li>Restart the editor</li>
  </ol>
</body>
</html>

Quick quiz 1 / 3

In <ol reversed><li>A</li><li>B</li><li>C</li></ol>, which number does A get?

Quick quiz 2 / 3

In <ol start="5"><li>x</li><li value="9">y</li><li>z</li></ol>, which number does z get?

Quick quiz 3 / 3

A page shows "1. 1. Preheat the oven" with a doubled number. What is the most likely cause?

What to remember

  • Use ol when reordering the items would change the meaning: steps, rankings, breadcrumbs.
  • The browser numbers items from their position, so never type numbers into the text.
  • start, reversed and value on an li change numbers for meaningful reasons; items after a value keep counting from it.
  • Style markers with CSS, and use the type attribute only when the marker letter itself carries meaning.

HTML Living Standard — Sections and Semantics — WHATWG

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Ordered Lists | Thuta Learning