Lists group related items so that readers can scan them quickly. HTML provides three kinds of list, and lists can be placed inside each other.
Unordered Lists
An unordered list shows its items with bullets. It begins with <ul>, and each item is an <li> element, which stands for list item. Use an unordered list when the order of the items does not matter, for example a list of subjects or a shopping list.
Ordered Lists
An ordered list numbers its items automatically. It begins with <ol>, and each item is again an <li> element. Use an ordered list when order matters, for example the steps of a recipe. The type attribute changes the numbering style to letters or Roman numerals, and the start attribute begins the count at another number.
Definition: List. A group of related items written with list tags, such as ol, ul or dl.
Definition Lists
A definition list pairs terms with descriptions. It begins with <dl>. Each term is placed in a <dt> element and its description in a <dd> element. Glossaries and lists of questions with answers are good uses.
Table 1.4: The three kinds of HTML list
| List | Tags | Use |
|---|---|---|
| Unordered | <ul> and <li> |
Items where order does not matter |
| Ordered | <ol> and <li> |
Items where order matters |
| Definition | <dl>, <dt> and <dd> |
Terms with descriptions |
Nested Lists
A list can be placed inside an item of another list to show sub-levels. The inner list must sit inside the <li> element of its parent item, before that item is closed. Nested lists are the basis of menus and course outlines.
Definition: Nested list. A list placed inside an item of another list to show sub-levels.
Example 1.4: A nested list of courses
<h3>Courses</h3>
<ul>
<li>Programming
<ol>
<li>HTML</li>
<li>CSS</li>
</ol>
</li>
<li>Databases</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>Language for page structure</dd>
</dl>
Output in the browser:
Styling and Using Lists
Browsers show a default marker: a disc for an unordered list and a number for an ordered list. The CSS property list-style-type changes the marker, for example to a square or to lower-case letters, and it can remove the markers altogether, which is what a navigation bar needs. A list item may hold any content, including links, images and paragraphs, so lists are used for menus, galleries and step-by-step guides. Keep each item short, and begin items in a similar way, for example with a verb, so that the list is easy to scan.
Common mistakes
- Placing text or other elements directly inside ul or ol without an li element.
- Putting an inner list between two li elements instead of inside one.
- Using an ordered list for items that have no real order.
- Using several br tags to imitate a list.
Key takeaways
- Use ul for bullets, ol for numbers and dl for terms with descriptions.
- Each item of ul and ol is an li element.
- A nested list sits inside the li of its parent item.
- Lists are also the base of navigation menus.
Practice questions
- Which tag starts a numbered list?
- Name the two tags used inside a definition list.
- Where must a nested list be placed?
Answers to the practice questions
- The ol tag.
- dt for the term and dd for the description.
- Inside an li element of the outer list.
Sources
- Official BCA syllabus (NEP 2025 scheme), Web Application Development, course code 25BCA405DS04, Unit I
