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.

The <ol> element accepts the following attributes.

AttributeDescription
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 reversed or reversed="reversed").

Possible values:

  • [Empty string]
  • reversed
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:

ValueDescription
1Represents decimal numbers (eg. 1. 2. 3. ... etc)
aRepresents lower case latin alphabet (eg. a. b. c. ... etc)
ARepresents upper case latin alphabet (eg. A. B. C. ... etc)
iRepresents lower case roman numerals (eg. i. ii. iii. ... etc)
IRepresents upper case roman numerals (eg. I. II. III. ... etc)

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 HTML 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 Handlers

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.

Most event handler content attributes can be used on all HTML elements, but some event handlers have specific rules around when they can be used and which elements they are applicable to.

For more detail, see HTML event handler content attributes.