HTML Ordered Lists
HTML ordered lists are created using the <ol>
tag and are lists of items that have a specific numerical order or sequence. They are three commonly used to present items where the order matters, such as:
- Step-by-step, ordered instructions.
- Chronologically numbered events or lists like this one!
- Top ten lists in articles and blog posts.
Key characteristics of ordered lists:
- List items: Individual items within the list are defined using the
<li>
tag, just like in unordered lists. - Numbering: Browsers typically display ordered lists with ascending numbers by default (1, 2, 3, etc.) to indicate the item’s position in the sequence.
- Nesting: Ordered lists can be nested within each other to create multi-level lists with hierarchical structures.
- Type of numbering: The
type
attribute can be used to change the numbering style (e.g.,type="A"
for uppercase letters,type="a"
for lowercase letters,type="I"
for uppercase Roman numerals,type="i"
for lowercase Roman numerals). - Starting number: The
start
attribute can be used to specify the starting number for the list (e.g.,start="5"
would start the list at 5). - Reversed numbering: The
reversed
attribute can be used to reverse the list (e.g.,<ol reversed>
for the opening tag would reverse the order).
Ordered List Example with the Type Attribute:
HTML:
<ol type="A"> <!-- This would display A., B., C. instead of a numbered list. -->
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Ordered List Example with the Start Attribute:
HTML:
<ol start="4"> <!-- This would display 4., 5., 6. instead of 1., 2., 3. -->
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Ordered List Example with the Reversed Attribute:
HTML:
<ol reversed> <!-- This would display 3., 2., 1. instead of 1., 2., 3. -->
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Nested Ordered Lists Example:
HTML:
<ol>
<li>Step 1
<ol>
<li>Sub-step 1</li>
<li>Sub-step 2</li>
</ol>
</li>
<li>Step 2</li>
</ol>
Remember:
- Use
<ul>
for unordered lists with bullet points or features like navigations. - Combine lists with text and other elements to create more complex content structures.
- You can apply CSS for further styling, such as custom numbering styles, spacing, alignment, and more.