HTML tagLists

<ol>

A numbered list in which the order of the items matters.

Display
block
Closing tag
Required
Permitted content
<li> elements (<script> and <template> are also allowed)
On this page

Example

#
HTML
<h3>How to publish your first page</h3>
<ol>
  <li>Create an <code>index.html</code> file.</li>
  <li>Add a heading and a few paragraphs.</li>
  <li>Check the page in the browser.</li>
  <li>Upload the file to a hosting service.</li>
</ol>
Preview

Definition and usage

#

The <ol> element (from ordered list) creates an ordered list. The browser numbers the <li> items itself, so after you add or remove a step the numbering still adds up. It’s a good choice for step-by-step instructions, recipes, rankings, and tables of contents.

You customize the numbering with attributes: start sets the first number, reversed reverses the order, and type swaps digits for letters or Roman numerals. You can give a single item its own number with the value attribute of the <li> element.

Ask yourself whether changing the order would break the meaning of the list. If so, choose <ol>; if not, <ul> is enough. Screen readers announce the list and the number of its items, so it’s easy to keep track of which step of the instructions you’re on.

Syntax

#
Syntax
<ol>
  <li>…</li>
  <li>…</li>
</ol>

Attributes

#
  • start

    integer

    The number the list starts from. It’s useful when a paragraph interrupts the list and the numbering should continue. It also works with letters and Roman numerals: start="3" together with type="a" starts at “c”.
  • reversed

    boolean attribute

    Reverses the numbering, so the list counts down. It suits rankings that end with the winner. The order of the elements in the code doesn’t change, only the numbers do.
  • type

    1 | a | A | i | I

    The kind of numbering: digits (1, the default), lowercase or uppercase letters (a, A), or lowercase or uppercase Roman numerals (i, I). Use it when the kind of number matters, for example in terms and conditions with points “a”, “b”, “c”. For purely visual purposes, the CSS list-style-type property is better.

The element also supports all global attributes, such as class, id, style and hidden.

Attributes in practice

#

start

integer

The number the list starts from. It’s useful when a paragraph interrupts the list and the numbering should continue. It also works with letters and Roman numerals: start="3" together with type="a" starts at “c”.

HTML
<p>We covered steps 1-3 in the previous lesson.</p>
<ol start="4">
  <li>Add a stylesheet.</li>
  <li>Set the colors and fonts.</li>
</ol>
Preview

reversed

boolean attribute

Reverses the numbering, so the list counts down. It suits rankings that end with the winner. The order of the elements in the code doesn’t change, only the numbers do.

HTML
<h4>Top 3 languages among our students</h4>
<ol reversed>
  <li>Python</li>
  <li>JavaScript</li>
  <li>HTML and CSS</li>
</ol>
Preview

type

1 | a | A | i | I

The kind of numbering: digits (1, the default), lowercase or uppercase letters (a, A), or lowercase or uppercase Roman numerals (i, I). Use it when the kind of number matters, for example in terms and conditions with points “a”, “b”, “c”. For purely visual purposes, the CSS list-style-type property is better.

HTML
<p>A course participant has the right to:</p>
<ol type="a">
  <li>access to all lessons,</li>
  <li>help from a mentor,</li>
  <li>a break from studying without losing progress.</li>
</ol>
Preview

Default CSS

#

Most browsers display this element with these default styles:

CSS
ol {
  display: block;
  list-style-type: decimal;
  margin-block: 1em;
  padding-inline-start: 40px;
}

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Don’t type numbers by hand in the item text. The browser numbers the items itself, and manual numbers fall out of sync after the first change.
  • You change the look of the numbers in CSS with li::marker, for example the color or font weight.
  • You can build multi-level numbering in the “1.2.3” style with CSS counters: counter-reset, counter-increment, and counters().

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.