Isi Kandungan
The Tag: An In-Depth Guide
Ordered lists in HTML are created using the <ol>
tag. An ordered list displays a list of items in a specific sequence or order, typically using numbers or letters as markers.
Usage of the tag
The <ol>
tag is used to create ordered lists. Each item in the list is defined by the <li>
tag, which stands for list item. Here is an example of an ordered list in HTML:
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
When rendered in the browser, the above code will produce:
- Item 1
- Item 2
- Item 3
Attributes of the tag
The <ol>
tag supports several attributes that allow you to customize the appearance and behavior of the ordered list. Some of the commonly used attributes include:
type
: Specifies the type of marker to use for the list items. The possible values are “1” (numbers), “A” (uppercase letters), “a” (lowercase letters), “I” (uppercase Roman numerals), and “i” (lowercase Roman numerals).start
: Specifies the starting value for the first item in the list.reversed
: Reverses the order of the list items.
Here is an example of an ordered list with customized attributes:
<ol type="A" start="3" reversed>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
When rendered in the browser, the above code will produce an ordered list with uppercase letters starting from “C” in reverse order:
- Item 1
- Item 2
- Item 3
Conclusion
The <ol>
tag is a useful element in HTML for creating ordered lists with a specific sequence or order. By using the <ol>
tag along with the <li>
tag, you can structure your content in a clear and organized manner. With the support of attributes, you can further customize the appearance and behavior of your ordered lists to suit your needs.
FAQs
What is the difference between and tags?
- tags?
The <ol>
tag is used to create ordered lists with a specific sequence or order, typically using numbers or letters as markers. On the other hand, the <ul>
tag is used to create unordered lists with no particular sequence or order, typically using bullets as markers.
Can I nest ordered lists within unordered lists?
Yes, you can nest ordered lists within unordered lists and vice versa. This allows you to create more complex list structures in your HTML documents.
How can I style ordered lists using CSS?
You can style ordered lists using CSS by targeting the <ol>
tag and its list items <li>
. You can change the font, color, background, margin, padding, and other properties to customize the appearance of your ordered lists.