HTML Lists
In this page:
<ul>
<li>Item</li>
</ul>
<ol>
<li>Item</li>
</ol>
Unordered Lists (ul and li)
Unordered lists are used when the order of the listed items does not matter. The browser displays these as bullet points. The list container uses the ul tag, and each list item is wrapped inside a li tag.
Example: Unordered Lists (ul and li)
<ul>
<li>Milk</li>
<li>Bread</li>
</ul>
Ordered Lists (ol and li)
If you are coding a set of instructions or list rankings, the sequence of items is critical. Ordered lists use the ol tag as the main container, and the browser automatically numbers each nested li item chronologically.
- Use ordered lists when teaching readers how to run a process or follow steps.
- Accepted attributes:
- type — 1 | a | A | i | I
- start — integer starting number
- reversed — boolean; counts down
- li value — integer number for that item
Example: Ordered Lists (ol and li)
<ol>
<li>Preheat oven</li>
<li>Mix ingredients</li>
</ol>
Customizing List Markers (type and start)
By default, ordered lists use numbers (1, 2, 3), and unordered lists use solid circular bullets.
You can customize these lists using attributes: the type attribute changes the numbering style (like Roman numerals or letters), and the start attribute sets a custom beginning number.
- Use the type attribute to display alphabetical steps for clean and varied sub-steps.
- Accepted attributes:
- type — 1 | a | A | i | I (on ol)
- start — integer (on ol)
- li value — integer (on li in ol)
- type on ul (disc | circle | square) is obsolete; use list-style-type
Example: Customizing List Markers (type and start)
<ol type="I" start="3">
<li>Third</li>
<li>Fourth</li>
</ol>
Nesting Lists Inside Lists
To represent complex directories or sub-categories, you can nest one list directly inside another. To do this, you place the secondary list container inside a specific li item of your primary list.
Example: Nesting Lists Inside Lists
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>
</li>
</ul>
Description Lists (dl, dt, dd)
When coding a dictionary, glossary, or product specifications list, standard bullets are not the best format.
Description lists group terms and descriptions using three tags: dl (description list), dt (definition term), and dd (definition description).
Example: Description Lists (dl, dt, dd)
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
</dl>
The reversed Attribute
The reversed attribute on an ordered list makes the numbering count downward instead of upward, without changing the actual order the list items appear in the HTML.
This is handy for countdowns or ranked lists where the most important item should appear last in the markup but still show the highest number, or vice versa.
- Combine reversed with a custom start value to count down from any specific number you choose.
- Accepted values:
- reversed — boolean attribute (present or reversed="")
- Works with ol only
- Combine with start to set the first number
Example: The reversed Attribute
<ol reversed start="3">
<li>Third</li>
<li>Second</li>
<li>First</li>
</ol>
Choosing the Right List Type
Use an unordered list when the order of items truly does not matter, like a set of features. Use an ordered list when sequence matters, like step-by-step instructions.
Use a description list when you are pairing terms with their definitions or explanations, like a glossary or FAQ.
Example: Choosing the Right List Type
<ul>
<li>Fast shipping</li>
</ul>
<ol>
<li>Add to cart</li>
</ol>
<dl>
<dt>SKU</dt>
<dd>Product code</dd>
</dl>
- Placing raw text or inline links directly inside ul or ol tags instead of nesting them inside li tags.
- Typing manual sequence numbers inside ordered list items, resulting in duplicate numbering on screens.
- Nesting secondary lists between list items rather than within a valid li element.
- Unordered lists (ul) display bullet points, and ordered lists (ol) display numbered sequences.
- Nesting lists is done by placing a new list container directly inside an existing li tag.
- Description lists (dl) use dt and dd tags to group terms and definitions semantically.
Unordered, ordered, and description lists are core elements supported by all browsers.
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists