On this page10 sections
Lecture 015: Lists
| Category | 3: Links, Images, Tables & Lists |
| Lecture | 015 of 048 |
| Estimated video length | 10 min |
| Target | HTML5 · any modern browser |
| Level | Beginner |
Shopping lists, recipe steps, menus: a lot of content is naturally a list. HTML has three kinds: bullet lists, numbered lists, and lists of terms with their meanings.
Learning Objectives
- Build bullet lists with
<ul>and numbered lists with<ol> - Nest one list inside another
- Change numbering with
start,reversedandtype - Write description lists with
<dl>,<dt>and<dd>
1. Unordered (Bullet) Lists
Use <ul> when the order doesn't matter. Each item is an <li> (list item).
Example
<h3>Shopping list</h3>
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Bread</li>
</ul>2. Ordered (Numbered) Lists
Use <ol> when the order does matter, such as steps.
Example
<h3>Make tea</h3>
<ol>
<li>Boil water</li>
<li>Add tea leaves</li>
<li>Add milk and sugar</li>
<li>Strain and serve</li>
</ol>The browser numbers the items for you. Add or remove a step and the numbers update themselves.
3. Changing the Numbering
| Attribute | Effect |
|---|---|
start="5" | Begin counting at 5 |
reversed | Count down |
type="A" | Use A, B, C… (also a, I, i) |
Example
<h3>Top 3 cities</h3>
<ol reversed>
<li>Islamabad</li>
<li>Lahore</li>
<li>Karachi</li>
</ol>
<h3>Choose one</h3>
<ol type="A">
<li>True</li>
<li>False</li>
</ol>4. Nested Lists
Put a whole new list inside an <li> to make sub-items.
Example
<ul>
<li>Fruit
<ul>
<li>Mango</li>
<li>Banana</li>
</ul>
</li>
<li>Vegetables
<ul>
<li>Spinach</li>
<li>Carrots</li>
</ul>
</li>
</ul>5. Description Lists
A <dl> pairs terms (<dt>) with their descriptions (<dd>), like a glossary.
Example
<dl>
<dt>HTML</dt>
<dd>The structure of a web page.</dd>
<dt>CSS</dt>
<dd>The styling of a web page.</dd>
</dl>Common Beginner Mistakes
1. Text directly inside <ul>. Only <li> elements may sit directly inside <ul> and <ol>.
2. Nested list outside the <li>. The inner <ul> must go inside the parent <li>,
before its </li>.
3. Typing the numbers yourself. <li>1. Boil water</li> in an <ol> shows "1. 1. Boil
water". Let <ol> do the counting.
4. Using lists just for indentation. If the content isn't really a list, use CSS for spacing.
Practice Questions
- Which list would you use for the steps of a recipe?
- What element is every list item wrapped in?
- Make a numbered list that starts at 10.
- Where does a nested list go?
- Which elements make a glossary of terms and meanings?
- Write a bullet list of three programming languages.
Practice Answers
- An ordered list,
<ol>. <li><ol start="10"><li>…</li></ol>- Inside the parent
<li>, before its closing</li>. <dl>,<dt>and<dd>.-
<ul> <li>Dart</li> <li>Python</li> <li>JavaScript</li> </ul>
Key Takeaways
<ul>for bullets (order doesn't matter),<ol>for numbers (order matters).- Every item is an
<li>; nested lists go inside an<li>. start,reversedandtypechange how an<ol>counts.<dl>/<dt>/<dd>pair terms with their meanings.