How to create an ordered list in HTML?


An ordered list is a numbered list of items. It gives you the ability to control the sequence number in the context. Allow us to group a set of related items in lists.

HTML supports ordered list and an unordered list. To create ordered list in HTML, we have to use the <ol> tag. We use <li> tag to start list of items within the ordered list tag. The list of items can be marked as numbers, lowercase letters uppercase letters, roman letters, etc.

The default order is numbers for list items in the context.

The <li> tag should be placed inside the <ol> tag to create the list of items.

We use type attribute of the <ol> tag, for creating an ordered list with numbers.

Syntax

Following is the syntax to create an ordered list in HTML.

<ol>
   <li>Item in list…</li>
   <li>Item in list…</li>
   <li>Item in list…</li>
</ol>

Example 1

Given below is an example to create an ordered list in HTML.

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <ol> <li>Mango</li> <li>Guava</li> <li>Apple</li> <li>Banana</li> </ol> </body> </html>

Following is the output for the above example program.

We can also use numbers, lowercase letters, uppercase letters, roman letters etc. to mark list of items.

Example 2

Given below is an example to create an ordered list in HTML. In here, we used uppercase letters to mark list of items.

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <ol type="A"> <li>Mangoe</li> <li>Guava</li> <li>Apple</li> <li>Banana</li> </ol> </body> </html>

Following is the output for the above example program.

Example 3

Given below is an example to create an ordered list in HTML. In here, we used lowercase letters, roman numbers to mark list of items.

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <ol type="a"> <li>Mango</li> <li>Guava</li> <li>Apple</li> <li>Banana</li> </ol> <ol type="I"> <li>c</li> <li>c++</li> <li>Java</li> <li>Python</li> </ol> <ol type="i"> <li>c</li> <li>c++</li> <li>Java</li> <li>Python</li> </ol> </body> </html>

Following is the output for the above example program.

Example 4

Following is the given code to create an ordered list of items numbered with numbers −

<!DOCTYPE html> <html> <head> <title>World Cup Teams</title> </head> <body> <h1>List of teams for World Cup</h1> <ol type = "1"> <li>India</li> <li>Australia</li> <li>South Africa</li> <li>New Zealand</li> <li>Pakistan</li> <li>Srilanka</li> <li>West Indies</li> <li>Bangladesh</li> </ol> </body> </html>

After compiling the above script, the output is obtained as −

Updated on: 24-Nov-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements