HTML Lists
Lists are collections of organized items, primarily divided into two types: ordered and unordered.
Ordered lists feature numbered items, displaying a clear sequence, like this:
1 | 1. Item A |
Unordered lists, on the other hand, use bullet points instead of numbers:
1 | • Item A |
<ol>
The <ol>
tag creates an ordered list container. It automatically generates numbers for each list item. This tag is ideal for content where the order matters, such as rankings.
1 | <ol> |
This code will number the items A, B, and C as 1, 2, and 3 respectively.
You can nest <ol>
or <ul>
tags within an <ol>
to create multi-level lists:
1 | <ol> |
This nested list will render as:
1 | 1. Item A |
The <ol>
tag has several useful attributes:
reversed: Creates a reverse-order list.
1
2
3
4
5<ol reversed>
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
</ol>This will number the items as 3, 2, 1.
start: Sets the starting number for the list.
1 | <ol start="5"> |
This will number the items as 5, 6, 7.
- type: Specifies the numbering style. Options include:
a
: lowercase lettersA
: uppercase lettersi
: lowercase Roman numeralsI
: uppercase Roman numerals1
: integers (default)
1 | <ol type="a"> |
This will label the items as a, b, c.
Note: Even when using letters, the start
attribute still uses integers:
1 | <ol type="a" start="3"> |
This will start the list at ‘c’.
<ul>
The <ul>
tag creates an unordered list container, using bullet points for each item. It’s best for lists where order doesn’t matter.
1 | <ul> |
This renders as a bulleted list.
Like <ol>
, you can nest <ul>
or <ol>
tags within <ul>
for multi-level lists.
<li>
The <li>
tag represents list items within <ol>
or <ul>
containers.
In ordered lists, <li>
has a value
attribute to set the item’s number:
1 | <ol> |
This will number the items as 1, 4, 5.
Definition Lists: <dl>
, <dt>
, <dd>
The <dl>
tag is a block-level element used to create a description list. It consists of term-definition pairs, where <dt>
defines the term (description term) and <dd>
provides the definition (description detail). Description lists are commonly used for glossaries or vocabularies.
1 | <dl> |
Both <dt>
and <dd>
are block-level elements. By default, <dd>
elements are indented beneath their corresponding <dt>
elements. The default rendering of the above code would look like this:
1 | CPU |
It’s perfectly valid to have multiple terms (<dt>
) sharing a single definition (<dd>
), or multiple definitions (<dd>
) for a single term (<dt>
).
For example:
1 | <dl> |
In this structure, terms A
and B
share the common definition C
, while term D
has two definitions, E
and F
.