Table of Contents
INTRODUCTION
List is a collection of items which are related. Lists create a well structured and easy-to-read information. In HTML there are 3 types of list available.
Ordered list <ol>
An HTML ordered list (<ol>) is used to display a list of items in a specific sequence,
typically numbered.
Ordered list uses some kind of sequence to list items. This sequence can be
letters, Numbers or Roman Numerals.
The HTML <ol> element is used to create ordered list.
The <li> element is used to create list items.
Syntax :
<ol>
<li> item1-content </li>
<li> item2-content </li>
<li> item3-content </li>
<li> item4-content </li>
</ol>
Example :
<ol>
<li> Chapter-1 </li>
<li> Chapter-2 </li>
<li> Chapter-3 </li>
<li> Chapter-4 </li>
</ol>
Output :
- Chapter-1
- Chapter-2
- Chapter-3
- Chapter-4
Tag Omission
The HTML <ol> element must have both start tag and end tag.
ATTRIBUTES
a. Type
It is used to specify the sequence type. The values it can take are:
- a - used for lowercase letters
- A - used for uppercase letters
- 1 - used for number (default)
- i - used for lowercase Roman Numerals
- I - used for Uppercase Roman Numerals
<ol type="a">
<li> Chapter-1 </li>
<li> Chapter-2 </li>
<li> Chapter-3 </li>
<li> Chapter-4 </li>
</ol>
- Chapter-1
- Chapter-2
- Chapter-3
- Chapter-4
b. reversed
This attribute is used to reverse the sequence of list. It is of boolean type ( possible values are True or False). If set to true, then list is reversed ie list items will be numbered in descending ordered (high to low).
<ol reversed >
<li> Chapter-1 </li>
<li> Chapter-2 </li>
<li> Chapter-3 </li>
<li> Chapter-4 </li>
</ol>
- Chapter-1
- Chapter-2
- Chapter-3
- Chapter-4
c. Start
This attribute specifies the starting Number Or Alphabet for sequence. For example to start sequence from Alphabet "E" use start="5" and type="A".
<ol start="5" type="A">
<li> Chapter-1 </li>
<li> Chapter-2 </li>
<li> Chapter-3 </li>
<li> Chapter-4 </li>
</ol>
- Chapter-1
- Chapter-2
- Chapter-3
- Chapter-4
Frequently Asked Questions(FAQ)
How to Make an Ordered List in HTML ?
<ol>
<li> item1-content </li>
<li> item2-content </li>
<li> item3-content </li>
<li> item4-content </li>
</ol>
How to create an ordered list in html with a decreasing index?
How many types of list are in html ?
- Ordered list <ol>
- unordered List <ul>
- Description List <dl>
Can list items contain content other than text ?
How can you change the numbering style of an ordered list ?
Can you nest ordered and unordered lists within each other ?
How can you increase the space between the number and the text in a list item ?
Why is my ordered list (<ol>) not displaying numbers ?
1. In CSS list-style-type: none; is Applied.
Sol: You need to remove list-style-type: none; or explicitly set it to decimal.
2. In CSS display: block; is set on <li> Items
Sol: Use list-style-type: decimal; or list-style-position: inside;
3. When an ordered list is placed inside another element that affects its styles, the numbers might disappear.
Sol: Ensure proper structure and correct nesting of <ol> inside parent elements.
4. Some browsers might not display numbers due to inherited styles.
Sol: Try adding list-style-type: decimal; styling to <ol> element.
Why do list markers disappear when display: block; is applied to <li> elements in a <ul> or <ol> ?
When you change display to block, The <li> now behaves like a standard block element and It loses the built-in list styling (i.e., numbers in <ol> or bullets in <ul>).
If you need display: block but still want the list markers, use list-style-position: inside;.
li {
display: block;
list-style-position: inside;
}
or If list-style-position doesn't work, you can add markers manually using ::before as shown below.
ol li{
display: block;
counter-increment: list-counter;
position: relative;
}
ol{
counter-reset: list-counter;
}
ol li::before{
content: counter(list-counter) ". ";
position: absolute;
left: -20px;
}