HTML - <ol>
The HTML <ol>
Element (or HTML Ordered List Element) represents an ordered list of items. Typically, ordered-list items are displayed with a preceding numbering, which can be of any form, like numerals, letters or Romans numerals or even simple bullets. This numbered style is not defined in the HTML description of the page, but in its associated CSS, using the list-style-type
property.
Examples
Simple example
<ol> <li>first item</li> <li>second item</li> <li>third item</li> </ol>
Above HTML will output:
- first item
- second item
- third item
Using the start attribute
<ol start="7"> <li>first item</li> <li>second item</li> <li>third item</li> </ol>
Above HTML will output:
- first item
- second item
- third item
Nesting lists
<ol> <li>first item</li> <li>second item <!-- Look, the closing </li> tag is not placed here! --> <ol> <li>second item first subitem</li> <li>second item second subitem</li> <li>second item third subitem</li> </ol> </li> <!-- Here is the closing </li> tag --> <li>third item</li> </ol>
Above HTML will output:
- first item
- second item
- second item first subitem
- second item second subitem
- second item third subitem
- third item
Nested <ol> and <ul>
<ol> <li>first item</li> <li>second item <!-- Look, the closing </li> tag is not placed here! --> <ul> <li>second item first subitem</li> <li>second item second subitem</li> <li>second item third subitem</li> </ul> </li> <!-- Here is the closing </li> tag --> <li>third item</li> </ol>
Above HTML will output:
- first item
- second item
- second item first subitem
- second item second subitem
- second item third subitem
- third item
Description
The HTML <ol>
Element (or HTML Ordered List Element) represents an ordered list of items. Typically, ordered-list items are displayed with a preceding numbering, which can be of any form, like numerals, letters or Romans numerals or even simple bullets. This numbered style is not defined in the HTML description of the page, but in its associated CSS, using the list-style-type
property.
There is no limitation to the depth and overlap of lists defined with the <ol>
and <ul>
elements.
<ol>
and <ul>
both represent a list of items. They differ in the way that, with the <ol>
element, the order is meaningful. As a rule of thumb to determine which one to use, try changing the order of the list items; if the meaning is changed, the <ol>
element should be used, else the <ul>
is adequate.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> elements |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parent elements | Any element that accepts flow content. |
DOM interface | HTMLOListElement |
Browser Compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 1.0 | 1.0 | 1.0 |
reversed attribute |
18 | 18.0 (18.0) | No support | No support | 5.2 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | 1.0 (1.0) | (Yes) | (Yes) | (Yes) |
reversed attribute |
(Yes) | 18.0 (18.0) | No support | No support | (Yes) |
See Also
- Other list-related HTML Elements:
<ul>
,<li>
,<menu>
and the obsolete<dir>
; - CSS properties that may be specially useful to style the
<ol>
element:- the
list-style
property, useful to choose the way the ordinal is displayed, - CSS counters, useful to handle complex nested lists,
- the
line-height
property, useful to simulate the deprecatedcompact
attribute, - the
margin
property, useful to control the indent of the list.
- the
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of '<ol>' in that specification. |
Living Standard | No change since last W3C snapshot, HTML5. |
HTML5 The definition of 'HTMLOListElement' in that specification. |
Recommendation | Added reversed and start attributed; un-deprecated type |
HTML 4.01 Specification The definition of '<ol>' in that specification. |
Recommendation | Deprecated compact and type . |
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/ol