back to top

The HTML Ordered List (<ol>) element is a versatile and essential tool within the HTML language. It is used to group a list of items in an orderly way where each item is marked with a label or a number. The list item tags (<li>) must be nested within the <ol> tags to define the order of items in the list.

Usage of the <ol> Tag

As the name implies, this tag is used primarily for ordering content on a webpage. This can include any number of things, such as a step-by-step guide, a simple to-do list, or ordered bullet points. The numbers automatically increment based on the order in which the items appear.

  1. Make coffee
  2. Drink coffee
  3. Repeat

The three-step process above would be perfectly ordered using the <ol> tag.

Attributes of the <ol> Tag

Like other HTML elements, the <ol> tag also has its own set of attributes which allow you to customize the appearance and functionality of the element.

  • Reversed: By using <ol reversed>, you can reverse the order of the list items.
  • Start: With the ‘start’ attribute, you can set the starting value of the list. For instance, <ol start=”10″> allows you to initiate the numbering from 10.
  • Type: With the ‘type’ attribute, you can use different types of numeration such as lower-alpha, upper-alpha, lower-roman, upper-roman, etc.

Styling the <ol> Tag

Besides the predefined attributes, you can utilise CSS (Cascading Style Sheets) to further style and customize your ordered list. You could include CSS both inline and in an external CSS file. The <ol> tag supports all global attributes and events in HTML.

For instance, we can style our ordered list and change the font, the color and the size of the numberings:


<ol style="font-family:Arial; color:#FF0000; font-size:20px;">
<li>Breakfast</li>
<li>Lunch</li>
<li>Dinner</li>
</ol>

HTML5 <ol> Attribute Improvements

HTML5 introduced a few changes to the <ol> element, which included the addition of a new value to the ‘type’ attribute as well as two new attributes: ‘start’ and ‘reversed’.

Today, the ‘type’ attribute includes ‘1’ for numbers, ‘A’ for uppercase letters, ‘a’ for lowercase letters, ‘I’ for uppercase Roman numerals, and ‘i’ for lowercase Roman numerals. The ‘start’ attribute allows you to specify the counting start number for the list, and ‘reversed’ makes the list count backwards.

Conclusion

The HTML <ol> element is indeed a very useful and powerful tool in building web pages. Despite its simplicity, its ability to organise web content into a sequence makes it an essential part of HTML. While there are other ways to create lists, the <ol> element uniquely allows for a logically ordered view, which can significantly enhance the user experience on a webpage.

Frequently Asked Questions about the <ol> element

  1. Do all lists in HTML need to be ordered?

    No, HTML allows both ordered (<ol>) and unordered (<ul>) lists. Unordered lists use bullet points instead of numbers or letters.

  2. Can I mix types of list elements in one list?

    Yes, you can have different types of list items (<li>) within one <ol> list.

  3. Can I use the <ol> element without any attributes?

    Yes, <ol> can be used without any attributes. The default setting will create an incrementally numbered list.

  4. Can I start my ordered list at zero?

    Yes, by using the ‘start’ attribute and setting it to zero: <ol start=”0″>.

  5. Can CSS be applied to the <ol> tag?

    Yes, all common CSS properties can be applied to the <ol> tag to customize the look of the list.

Subscribe

Related articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here