Lists
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — Introduction to HTML Lists
Lists are a fundamental way to organize information in HTML. There are three main types of lists: - Unordered lists (bulleted) - Ordered lists (numbered) - Definition lists (term and description pairs)
Let's start with the unordered list UL (<ul>). This creates a bulleted list where each item starts with a bullet point. Each list item is defined with the <li> tag.
<!DOCTYPE html>
<html>
<body>
<h2>Starter Codémons</h2>
<ul>
<li>Aquachu</li>
<li>Pyrochu</li>
<li>Florachu</li>
</ul>
</body>
</html>Important List Rules
Always remember that list items (<li>) must be inside a list container (<ul>, <ol>, or <dl>). Never use list items on their own without a parent list element.
Exercise 2 — Ordered Lists
Ordered lists (<ol>) create numbered lists where items appear in a specific sequence.
Like unordered lists, each item is defined with the <li> tag.
<!DOCTYPE html>
<html>
<body>
<h2>How to Train Your Codémon</h2>
<ol>
<li>Choose your starter Codémon</li>
<li>Learn basic commands</li>
<li>Earn badges</li>
</ol>
</body>
</html>Notice how the browser automatically numbers each item in sequence. You don't need to add the numbers yourself!
Exercise 3 — Choosing the Right List Type
Which type of HTML list would be most appropriate for displaying a recipe's step-by-step cooking instructions?
<ol><ul><dl><li>Hint : Think about whether the sequence of items matters. Would we use an ordered list or an unordered list?
Exercise 4 — Definition Lists
Definition lists (<dl>) are used to display term-description pairs. They're perfect for glossaries, dictionaries, or any content with terms and their explanations.
A definition list uses three elements:
- <dl> - The container for the list
- <dt> - Definition term (the word being defined)
- <dd> - Definition description (the explanation)
<!DOCTYPE html>
<html>
<body>
<h2>Codémon Types Glossary</h2>
<dl>
<dt>Water</dt>
<dd>Strong against fire types. Weak against plant types.</dd>
<dt>Fire</dt>
<dd>Strong against plant types. Weak against water types.</dd>
<dt>Plant</dt>
<dd>Strong against water types. Weak against fire types.</dd>
</dl>
</body>
</html>Multiple Descriptions
You can have multiple <dd> elements for a single <dt> term if you need to provide multiple descriptions for one term.
Exercise 5 — Match List Elements with Their Purpose
Match each HTML list element with its correct purpose:
<ul><ol><li><dl>Exercise 6 — Choosing the Right List Type
Which type of HTML list would be most appropriate for a glossary of Codémon terminology with terms and their definitions?
<dl><ul><ol><li>Hint : Think about which list type is specifically designed to handle pairs of related information, like terms and their definitions.
Exercise 7 — Complete the List Structure
Complete the HTML code to create an unordered list of Codémon types.
Hint : Remember the proper structure: a list container (ul or ol) with li elements inside it for each list item.
Exercise 8 — List Types and Their Uses
Match each list type with its most appropriate use case:
<ul><ol><dl><li>Exercise 9 — Creating a Definition List
Complete the HTML code to create a definition list for Codémon abilities.
Hint : Remember the structure: <dl> contains term-description pairs, where each term is in <dt> and each description is in <dd>.
Exercise 10 — List Best Practices
Which of the following is NOT a valid way to use HTML lists?
Hint : Think about the required parent-child relationships between list elements. Can list items exist on their own?