<ol>: The Ordered List element #
::: section-content
The <ol>
HTML element represents an ordered list of items
— typically rendered as a numbered list.
:::
Try it #
::: section-content ::: iframe ::: {.output-header .border-rounded-top}
HTML Demo: <ol> #
Reset :::
::: {#warning-no-script .warning-container} ::: warning The interactive example cannot be shown because JavaScript is disabled. ::: :::
::: {#warning-mathml-not-supported .warning-container .hidden} ::: warning The interactive example cannot be shown because MathML is not supported by your browser. ::: :::
::: {#editor-container .editor-container .tabbed-shorter .hidden .border-rounded-bottom editor-type=“tabbed”} ::: {#tab-container .section .tabs} ::: {#tablist .tab-list role=“tablist”} HTML
CSS
JavaScript :::
::: {#html-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“html” aria-hidden=“true”} ::: {#html-editor}
- Mix flour, baking powder, sugar, and salt.
- In another bowl, mix eggs, milk, and oil.
- Stir both mixtures together.
- Fill muffin tray 3/4 full.
- Bake for 20 minutes.
::: {#css-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“css” aria-hidden=“true”} ::: {#css-editor} li { font: 1rem ‘Fira Sans’, sans-serif; margin-bottom: 0.5rem; } ::: :::
::: {#js-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“js” aria-hidden=“true”} ::: {#js-editor} ::: ::: :::
::: {#output .output-container}
Output #
::: :::
::: {.section .console-container .hidden aria-hidden=“true”}
Console Output #
![] clear console
::: {#console .console} ::: :::
::: {#html-output .output .editor-tabbed} %html-content% ::: ::: :::
Attributes #
::: section-content This element also accepts the global attributes.
reversed
This Boolean attribute specifies that the list's items are in reverse order. Items will be numbered from high to low.
start
An integer to start counting from for the list items. Always an Arabic numeral (1, 2, 3, etc.), even when the numbering
type
is letters or Roman numerals. For example, to start numbering elements from the letter "d" or the Roman numeral "iv," usestart="4"
.type
Sets the numbering type:
a
for lowercase lettersA
for uppercase lettersi
for lowercase Roman numeralsI
for uppercase Roman numerals1
for numbers (default)
The specified type is used for the entire list unless a different
type
attribute is used on an enclosed<li>
element.::: {#sect1 .notecard .note} Note: Unless the type of the list number matters (like legal or technical documents where items are referenced by their number/letter), use the CSS
list-style-type
property instead. ::: :::
Usage notes #
::: section-content Typically, ordered list items display with a preceding marker, such as a number or letter.
The <ol>
and
<ul>
elements may nest as deeply as desired,
alternating between <ol>
and <ul>
however you like.
The <ol>
and
<ul>
elements both represent a list of items. The
difference is with the <ol>
element, the order is meaningful. For
example:
- Steps in a recipe
- Turn-by-turn directions
- The list of ingredients in decreasing proportion on nutrition information labels
To determine which list to use, try changing the order of the list
items; if the meaning changes, use the <ol>
element — otherwise you
can use
<ul>
.
:::
Examples #
Simple example #
::: section-content ::: code-example [html]{.language-name}
<ol>
<li>Fee</li>
<li>Fi</li>
<li>Fo</li>
<li>Fum</li>
</ol>
:::
Result #
::: {#sect2 .code-example} ::: iframe ::: ::: :::
Using Roman Numeral type #
::: section-content ::: code-example [html]{.language-name}
<ol type="i">
<li>Introduction</li>
<li>List of Grievances</li>
<li>Conclusion</li>
</ol>
:::
Result #
::: {#sect3 .code-example} ::: iframe ::: ::: :::
Using the start attribute #
::: section-content ::: code-example [html]{.language-name}
<p>Finishing places of contestants not in the winners' circle:</p>
<ol start="4">
<li>Speedwalk Stu</li>
<li>Saunterin' Sam</li>
<li>Slowpoke Rodriguez</li>
</ol>
:::
Result #
::: {#sect4 .code-example} ::: iframe ::: ::: :::
Nesting lists #
::: section-content ::: code-example [html]{.language-name}
<ol>
<li>first item</li>
<li>
second item
<!-- closing </li> tag is not here! -->
<ol>
<li>second item first subitem</li>
<li>second item second subitem</li>
<li>second item third subitem</li>
</ol>
</li>
<!-- Here's the closing </li> tag -->
<li>third item</li>
</ol>
:::
Result #
::: {#sect5 .code-example} ::: iframe ::: ::: :::
Unordered list inside ordered list #
::: section-content ::: code-example [html]{.language-name}
<ol>
<li>first item</li>
<li>
second item
<!-- closing </li> tag is not here! -->
<ul>
<li>second item first subitem</li>
<li>second item second subitem</li>
<li>second item third subitem</li>
</ul>
</li>
<!-- Here's the closing </li> tag -->
<li>third item</li>
</ol>
:::
Result #
::: {#sect6 .code-example} ::: iframe ::: ::: :::
Technical summary #
::: section-content
Content categories | Flow content, and
if the <ol> element's children include at least one
<li> element, palpable content. |
---|---|
Permitted content | Zero or more <li> , <script> and <template> elements. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts flow content. |
Implicit ARIA role | list |
Permitted ARIA roles | directory ,
group ,
listbox ,
menu ,
menubar ,
none ,
presentation ,
radiogroup ,
tablist ,
toolbar ,
tree |
DOM interface | HTMLOListElement |
Specifications #
::: _table #
Specification #
HTML Standard
[#
the-ol-element]{.small}
:::
Browser compatibility #
::: _table Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
ol
1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
compact
1 12 1 Yes 15 3 4.4 18 4 14 2 1.0
reversed
18 ≤79 18 No 15 6 4.4 18 18 14 6 1.0
start
1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
type
1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
:::
See also #
::: section-content
- Other list-related HTML Elements:
<ul>
,<li>
,<menu>
- CSS properties that may be specially useful to style the
<ol>
element:- the
list-style
property, to choose the way the ordinal displays - CSS counters, to handle complex nested lists
- the
line-height
property, to simulate the deprecatedcompact
attribute - the
margin
property, to control the list indentation :::
- the
::: _attribution
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5
or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol{._attribution-link}
:::