HTML Ordered List

An HTML Ordered List, also known as a Numbered List, is utilized to display list items in a specific, structured sequence. Whether you are outlining a recipe, enumerating steps in an algorithm, or highlighting the top features, implementing the <ol> tag ensures that your content will be exhibited in a sequential manner that conveys a sense of hierarchy or significance.

All content in a numbered list is wrapped in an <li> (list item) element. The list can have default numbering using Arabic numerals like 1, 2, 3... Alternatively, it is possible to use alphabetic and Roman numerals for numbering, which can also be implemented using HTML.

Example of <ol> in HTML

HTML Ordered List Example

Consider an instance of an HTML ordered list showcasing four topics in a numbered format. In this case, the type="1" attribute is omitted as it defaults to this type.

Example

Example

<ol>

 <li>HTML</li>

 <li>Java</li>

 <li>JavaScript</li>

 <li>SQL</li>

</ol>

Output:

Output

1. HTML

2. Java

3. JavaScript

4. SQL

Ordered List Types Using type Attribute

Changing the appearance of numbers is possible by utilizing the type attribute within the ol tag. There are five commonly used values for this purpose:

Type Description
"1" Default. Numbers (1, 2, 3...)
"A" Uppercase letters (A, B, C...)
"a" Lowercase letters (a, b, c...)
"I" Uppercase Roman numerals (I, II, III)
"i" Lowercase Roman numerals (i, ii, iii)

Examples of Different List Types:

Example

Example

<ol type="A">

 <li>HTML</li>

 <li>Java</li>

 <li>JavaScript</li>

 <li>SQL</li>

</ol>

Output:

Output

A. HTML	

B. Java		

C. JavaScript	

D. SQL

Reiterate the preceding instructions by using the type "a", "I", or "i" for varying formats.

Using the start Attribute

The start attribute is used to specify the starting number or marker for a list. This feature is particularly useful when continuing a list from a previous one or adjusting the numbering of list items.

Example

Example

<ol type="i" start="5">

 <li>HTML</li>

 <li>Java</li>

 <li>JavaScript</li>

 <li>SQL</li>

</ol>

Output:

Output

v. HTML

vi. Java

vii. JavaScript

viii. SQL

You have the flexibility to combine type and start attributes in the following way:

  • When type="A" and start="5", it will begin from "E".
  • When type="I" and start="10", it will commence from "X".
  • Reversing List Order with reversed

The attribute called "reversed," introduced in HTML5, is used to display list items in the opposite order.

Example

Example

<ol reversed>

<li>HTML</li>

<li>Java</li>

<li>JavaScript</li>

<li>SQL</li>

 </ol>

Output:

Output

4. HTML

3. Java

2. JavaScript

1. SQL

You can combine reversed with start and type:

Example

Example

<ol type="I" start="10" reversed>

  <li>HTML</li>

  <li>CSS</li>

  <li>JavaScript</li>

</ol>

Output:

Output

X. HTML

IX. CSS

VIII. JavaScript

Nesting Ordered and Unordered Lists

HTML allows for the nesting of lists within lists, enabling the creation of hierarchical structures of lists.

Example: Nested Ordered List

Example

Example

<ol type="I">

  <li>

    Chapter 1

    <ol type="a">

      <li>Introduction</li>

      <li>Basics</li>

    </ol>

  </li>

  <li>

    Chapter 2

    <ol type="a">

      <li>Advanced Concepts</li>

      <li>Practice</li>

    </ol>

  </li>

</ol>

Output:

Output

I. Chapter 1

  a. Introduction

  b. Basics

II. Chapter 2

  a. Advanced Concepts

  b. Practice

Example: Mixed Nested Lists

Example

Example

<ol>

  <li>

    Prepare ingredients:

    <ul>

      <li>Flour</li>

      <li>Eggs</li>

      <li>Butter</li>

    </ul>

  </li>

  <li>Mix and cook.</li>

  <li>

    Serve with toppings:

    <ul>

      <li>Syrup</li>

      <li>Fruits</li>

    </ul>

  </li>

</ol>

Output:

Output

1. Prepare ingredients:

 • Flour

 • Eggs

 • Butter

2. Mix and cook.

3. Serve with toppings:

 • Syrup

 • Fruits

Styling Ordered Lists with CSS

Increased visual customization can also be accomplished using CSS list styles:

Example

Example

<ol style="list-style-type: upper-roman;">

  <li>HTML</li>

  <li>CSS</li>

  <li>JavaScript</li>

</ol>



<ol style="line-height:180%;">

  <li>Python</li>

  <li>Go</li>

</ol>

Output:

Output

Using list-style-type: upper-roman;

I. HTML

II. CSS

III. JavaScript



Using line-height:180%; for spacing

1.	Python

2.	Go

CSS supports a wide range of list-style types:

  • decimal, decimal-leading-zero, lower-roman, upper-roman
  • lower-alpha, upper-alpha, Armenian, Georgian, Hebrew
  • Custom styles using list-style-image or ::marker for advanced design
  • Advanced Customization with CSS

CSS provides enhanced flexibility beyond the default list styles. An illustration of this is the ability to customize list markers directly by utilizing the ::marker pseudo-element in the following manner:

Example

<style>

  ol.custom-markers::marker {

    color: red;

    font-weight: bold;

  }

</style>



<ol class="custom-markers">

  <li>Design</li>

  <li>Develop</li>

  <li>Deploy</li>

</ol>

Another option is to utilize list-style-image property to substitute bullets or numbers with personalized icons:

Example

<ol style="list-style-image: url('star.png');">

  <li>Plan</li>

  <li>Execute</li>

  <li>Test</li>

</ol>

Accessibility Considerations for Ordered Lists

Numbered lists offer visual structure and enhance accessibility when implemented correctly. Screen readers recognize the <ol> tag as an indication of sequential items that are arranged in a specific order. This makes ordered lists ideal for providing directions, tutorials, or any content where the sequence is crucial.

In order to improve accessibility, it is essential to ensure that significant content is enclosed within appropriate HTML tags, and these tags should not serve the purpose of formatting lists. Additionally, incorporating numbered lists into semantic HTML (e.g., utilizing section headings and ARIA labels when necessary) assists in ensuring that your content is accessible and inclusive across various devices and with the aid of assistive technologies.

Supporting Browsers

Element Chrome IE Firefox Opera Safari
<ol> Yes Yes Yes Yes Yes

Conclusion

The HTML <ol> tag offers a straightforward yet valuable way to present information in a specific order. Whether you are outlining steps, defining chapter hierarchies, or ranking items, you have the ability to personalize the look and sequence of list items through attributes like type, start, and reversed. While regular lists are already versatile for organizing content in a meaningful manner, the addition of nesting and CSS formatting enhances the flexibility of ordered lists.

Input Required

This code uses input(). Please provide values below: