HTML <ol> Tag
<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.
<ol> <li>List item...</li> <li>List item...</li> <li>List item...</li> </ol>
Basic Ordered List
Here's an example of using
<li> elements to create an ordered list.
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
Also note that the ordinal value of the
start attribute must be a valid integer.
You can use the
reversed attribute to reverse the order of the list (i.e. make it a descending list).
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.
You can use the
type attribute to specify the type of marker to be used in the list
type attribute accepts the following values:
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.
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.
list-style property is a shortcut property. It allows you to apply multiple properties to your list items.
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.
<ol> element accepts the following attributes.
This table shows the attributes that are specific to the
|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
|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.
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.
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.
For a full explanation of these attributes, see HTML 5 event handler content attributes.
Differences Between HTML 4 & HTML 5
HTML5 introduced the
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.
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.
<ol reversed="" start="" type="" accesskey="" class="" contenteditable="" contextmenu="" dir="" draggable="" dropzone="" hidden="" id="" itemid="" itemprop="" itemref="" itemscope="" itemtype="" lang="" spellcheck="" style="" tabindex="" title="" translate="" onabort="" onautocomplete="" onautocompleteerror="" onblur="" oncancel="" oncanplay="" oncanplaythrough="" onchange="" onclick="" onclose="" oncontextmenu="" oncuechange="" ondblclick="" ondrag="" ondragend="" ondragenter="" ondragexit="" ondragleave="" ondragover="" ondragstart="" ondrop="" ondurationchange="" onemptied="" onended="" onerror="" onfocus="" oninput="" oninvalid="" onkeydown="" onkeypress="" onkeyup="" onload="" onloadeddata="" onloadedmetadata="" onloadstart="" onmousedown="" onmouseenter="" onmouseleave="" onmousemove="" onmouseout="" onmouseover="" onmouseup="" onmousewheel="" onpause="" onplay="" onplaying="" onprogress="" onratechange="" onreset="" onresize="" onscroll="" onseeked="" onseeking="" onselect="" onshow="" onsort="" onstalled="" onsubmit="" onsuspend="" ontimeupdate="" ontoggle="" onvolumechange="" onwaiting="" > </ol>
Here are the official specifications for the
- 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.