HTML <ol> Tag
The HTML <ol>
tag is used for specifying an ordered list.
Ordered lists are usually ordered by numbers (1. 2. 3...), letters (A. B. C...), roman numerals (i. ii. iii...) etc.
In an ordered list, the list items are ordered, such that changing the order would change the meaning of the list (or document).
A good example of an ordered list is a list of instructions, with each list item representing a different step that needs to be done in that order. Changing the order would change the meaning of the instructions.
The <ol>
element is used with the <li>
element. The <ol>
tag declares the ordered list, and the <li>
tag declares each list item.
Syntax
The <ol>
tag is written as <ol>
</ol>
with any number of <li>
tags and/or script-supporting elements (<script>
and <template>
) enclosed between the start and end tags.
Like this:
Examples
Basic Ordered List
Here's an example of using <ol>
and <li>
elements to create an ordered list.
The start
Attribute
You can use the start
attribute to specify an ordinal value for which to start the first item. All subesquent list items increment their value from that initial value (unless you override it with a new value, by using the value
attribute inside an <li>
element).
Also note that the ordinal value of the start
attribute must be a valid integer.
The reversed
Attribute
You can use the reversed
attribute to reverse the order of the list (i.e. make it a descending list).
The reversed
attribute is a boolean attribute, which means that, its mere presence effects its purpose. In other words, you don't need to provide a value. Simply including the word reversed
is sufficient.
The type
Attribute
You can use the type
attribute to specify the type of marker to be used in the list
The type
attribute accepts the following values: decimal
, lower-alpha
, upper-alpha
, lower-roman
, upper-roman
.
The type
attribute was deprecated in HTML 4, however, it is supported in HTML5. Some browsers don't display this attribute properly at the time of writing.
Applying Styles
You can use the CSS list-style
, list-style-image
, list-style-position
, and list-style-type
properties to change the styles of the <ol>
element.
Roman Numerals
This example uses the list-style-type
property to specify roman numerals.
Position of List Item
This example uses the list-style-position
property to specify the position of the list items.
The list-style
Property
The list-style
property is a shortcut property. It allows you to apply multiple properties to your list items.
Example:
Attributes
Attributes can be added to an HTML element to provide more information about how the element should appear or behave.
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes.
The <ol>
element accepts the following attributes.
Element-Specific Attributes
This table shows the attributes that are specific to the <ol>
tag/element.
Attribute | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reversed | Specifies that the list is a descending list (...3, 2, 1).
This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either Possible values:
|
||||||||||||
start | Specifies the count of the first list item. Must be an ordinal number. | ||||||||||||
type | Specifies the kind of marker to use in the list. If specified, this attribute must have one of the following values:
Note: The CSS list-style-type property is often more appropriate for specifying the marker type. |
Global Attributes
The following attributes are standard across all HTML5 elements. Therefore, you can use these attributes with the <ol>
tag , as well as with all other HTML tags.
- accesskey
- class
- contenteditable
- contextmenu
- dir
- draggable
- dropzone
- hidden
- id
- inert
- itemid
- itemprop
- itemref
- itemscope
- itemtype
- lang
- spellcheck
- style
- tabindex
- title
- translate
For a full explanation of these attributes, see HTML 5 global attributes.
Event Handler Content Attributes
Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.
Below are the standard HTML5 event handler content attributes.
Again, you can use any of these with the <ol>
element, as well as any other HTML5 element.
- onabort
- oncancel
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragexit
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onformchange
- onforminput
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onpause
- onplay
- onplaying
- onprogress
- onratechange
- onreadystatechange
- onscroll
- onseeked
- onseeking
- onselect
- onshow
- onstalled
- onsubmit
- onsuspend
- ontimeupdate
- onvolumechange
- onwaiting
For a full explanation of these attributes, see HTML 5 event handler content attributes.
Differences Between HTML 4 & HTML 5
HTML5 introduced the reversed
attribute.
The type
and start
attributes were deprecated in HTML 4, however, they are supported in HTML5.
HTML5 does not support the compact
attribute, which was deprecated in HTML 4.
To see more detail on the two versions see HTML5 <ol>
Tag and HTML4 <ol>
Tag. Also check out the links to the official specifications below.
Template
Here's a template for the <ol>
tag with all available attributes for the tag (based on HTML5). These are grouped into attribute types, each type separated by a space. In many cases, you will probably only need one or two (if any) attributes. Simply remove the attributes you don't need.
For more information on attributes for this tag, see HTML5 <ol>
Tag and HTML4 <ol>
Tag.
Tag Details
For more details about the <ol>
tag, see HTML5 <ol>
Tag and HTML4 <ol>
Tag.
Specifications
Here are the official specifications for the <ol>
element.
- HTML5 Specification (W3C)
- HTML Living Standard (WHATWG)
- Current W3C Draft (the next version that is currently being worked on)
- HTML 4 (W3C)
What's the Difference?
W3C creates "snapshot" specifications that don't change once defined. So the HTML5 specification won't change once it becomes an official recommendation. WHATWG on the other hand, develops a "living standard" that is updated on a regular basis. In general, you will probably find that the HTML living standard will be more closely aligned to the current W3C draft than to the HTML5 specification.