The <ol> tag is used in HTML to define an ordered list. It allows you to display a list in which the items are presented in a specific order (for example, numbered from 1 to n).
Structure and syntax of the <ol> tag
Basic structure and syntax
Here is the basic syntax of the <ol> tag:
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>The <ol> tag is used to contain a series of list items. Each item in the list is defined using the <li> tag.
Usage example
Here is an example of using the <ol> tag for an ordered list:
<ol>
<li>Start the project</li>
<li>Analyze the needs</li>
<li>Develop the code</li>
<li>Test the application</li>
</ol>In this example, each item in the list is automatically numbered by the browser.
Attributes
The <ol> tag can accept certain attributes to customize the display of the list:
type: Defines the type of numbering (for example,1for numbers,afor letters, etc.).start: Specifies the starting number of the list. By default, the list starts at 1.
Example of attributes
<ol type="a" start="3">
<li>Third item</li>
<li>Fourth item</li>
</ol>In this example, the list starts with the letter "c" (corresponding to 3) and uses letters to number the items.
Difference with other similar tags
<ul>: The<ul>tag is used for an unordered list, meaning the items are displayed without any specific order (usually with bullets).<li>: The<li>tag is used to define the items in an ordered list (<ol>) or unordered list (<ul>).<dl>: Finally, the<dl>tag is used to create definition lists exclusively.
Browser compatibility
The <ol> tag is supported by all modern browsers.
| Browser | Compatibility |
|---|---|
| Chrome | Yes |
| Firefox | Yes |
| Safari | Yes |
| Edge | Yes |
| Internet Explorer | Yes |