<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)
Example
#<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>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
#<ol>
<li>…</li>
<li>…</li>
</ol>Attributes
#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 withtype="a"starts at “c”.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.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 CSSlist-style-typeproperty is better.
The element also supports all global attributes, such as class, id, style and hidden.
Attributes in practice
#start
integerThe 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”.
<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>reversed
boolean attributeReverses 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.
<h4>Top 3 languages among our students</h4>
<ol reversed>
<li>Python</li>
<li>JavaScript</li>
<li>HTML and CSS</li>
</ol>type
1 | a | A | i | IThe 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.
<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>Default CSS
#Most browsers display this element with these default styles:
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, andcounters().
Related entries
#- <ul>A bulleted list in which the order of the items doesn’t matter.
- <li>A single item of a `<ul>`, `<ol>`, or `<menu>` list.
- <dl>A description list: name and description pairs, for example a glossary of terms or technical data.
- <menu>A list of commands, for example a toolbar with buttons. It works like `<ul>`.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.