Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 122 ยท Lists

Ordered List Options

Control numbering in HTML ordered lists. Start at any number, count down with reversed, choose letters or Roman numerals with type, and set item numbers with value.

An ordered list numbers its items 1, 2, 3 without any help from you. That covers most cases. But sometimes you need more control: a list that continues after an interruption, a countdown, a legal clause numbered "a, b, c", or a list where some numbers are skipped.

<ol> has three attributes for that, start, reversed and type, and <li> has one more, value. Together they let you produce almost any numbering without typing a single number yourself.

Starting at a different number: start

The start attribute sets the number of the first item. The rest count up from there:

Continuing a list with start

The two lists are separated by a paragraph, but the steps continue: 4, 5, 6. Change start="4" to another number and watch the numbering follow.

A few details:

  • start takes an integer. Zero and negative numbers are allowed: start="0" gives 0, 1, 2.
  • start is always a number, even when the list uses letters or Roman numerals. With letters, start="3" begins at "c".

Don't fake a continued list. Ending one list and starting another with start is right when there is real content between them, like the paragraph above. If there isn't, keep all the items in one <ol>.

Counting down: reversed

reversed is a boolean attribute: present means on. It makes the list count down instead of up. Without a start, the first item gets the number of items in the list, so the last item is always 1:

A top-five countdown

Add a sixth trail to the first list. The numbers shift automatically, and the winner at the bottom stays number 1. That's exactly why reversed beats typing the numbers by hand.

Note that reversed only changes the numbers, not the order in which the items appear. The first item in your code is still shown first.

Letters and Roman numerals: type

The type attribute picks the kind of marker:

type Numbering
1 1, 2, 3, 4 (default)
a a, b, c, d
A A, B, C, D
i i, ii, iii, iv
I I, II, III, IV
HTML
<ol type="a">
  <li>The tenant pays the rent by the 5th of each month.</li>
  <li>The landlord handles all repairs to the roof.</li>
</ol>

You learned in Lists that CSS's list-style-type changes markers too. So why does HTML keep a type attribute? Because sometimes the numbering style is part of the meaning, not just the look. In a contract, someone might write "see clause b". If a stylesheet were missing or changed, numbers would no longer match that reference. Use type when the marker style matters to the content, and CSS when it's purely decoration.

CSS still wins. The type attribute acts like a default style. If your stylesheet sets list-style-type on the same list, the CSS value is used.

Setting individual numbers: value

The value attribute on an <li> gives that item a specific number. The items after it continue counting from the new value:

Skipping numbers with value

In the race results, two runners tie for second place, so both get value="2". The next runner is fourth, not third, so value="4" resets the count and Sofia follows as 5.

In the errata list, only certain rules are mentioned. Each value matches the real rule number, and the last item simply continues from 7 to VIII. As with start, value is always written as a plain integer, even when the list shows Roman numerals.

value also works in reversed lists: the item gets the given number, and the items after it keep counting down from there.

Putting the options together

You can combine all four. A reversed list of letters that starts at "e":

HTML
<ol type="a" reversed start="5">
  <li>Fifth choice</li>
  <li>Fourth choice</li>
  <li>Third choice</li>
</ol>

That produces e, d, c. When you combine options, keep asking whether the numbering carries meaning. If the numbers are only decoration, CSS counters and list-style-type give you even more control, and the HTML stays simple.

Numbers that people can rely on

Generated numbers aren't only convenient for you. Screen readers announce them along with each item ("3, Leave it in the fridge"), so a listener always knows which step they're on, and the attributes in this lesson make sure those announced numbers match what sighted readers see. When someone refers to "step 5" in a support email or a comment, both of you are talking about the same item.

One caveat: when visitors copy a list and paste it somewhere else, whether the numbers come along depends on the browser and the destination. If readers are likely to quote specific items, mention the number in nearby text too, for example "see step 5 above".

Never type numbers into the items. Writing <li>1. Preheat the oven</li> inside an <ol> displays "1. 1. Preheat the oven". Switching to a <ul> with list-style: none and hand-typed numbers loses the meaning instead. Let <ol> and its attributes do the numbering.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A list continues after a paragraph and should start at 7. What do you write?

    start sets the number of the first item. value belongs on <li>, and type chooses the kind of marker.
  2. 2. An ol has the reversed attribute, no start and four items. What number does the first item show?

    Without start, a reversed list begins at the number of items, so the last item ends on 1.
  3. 3. How do you make a list begin at "c" when it uses type="a"?

    start and value always take integers. The third letter of the alphabet is c, so start="3".
  4. 4. Why does HTML keep the type attribute on ol when CSS can change markers?

    When text refers to "item b", the marker style matters even without CSS. For decorative changes, use list-style-type.

Summary

  • start sets the first number of an <ol>; it is always an integer and may be zero or negative.
  • reversed counts down; without start, the last item ends at 1.
  • type (1, a, A, i, I) chooses the numbering style when that style is part of the meaning.
  • value on an <li> sets that item's number, and the following items continue from it.
  • Never type numbers into the items; let the list number itself.

Next lesson: Description Lists.