Module 6 of 12

📖 HTML Lists

Lists are fundamental for organizing content. HTML offers three types of lists.

1. Unordered Lists (<ul>)

For items where order doesn't matter. Browsers display bullets by default.

<ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> </ul>

Result:

2. Ordered Lists (<ol>)

For sequential items. Browsers display numbers by default.

<ol> <li>Preheat oven to 180°C</li> <li>Mix flour and sugar</li> <li>Add eggs and milk</li> <li>Bake for 25 minutes</li> </ol>

Ordered List Attributes

<!-- Start from a specific number --> <ol start="5"> <li>Item 5</li> <li>Item 6</li> </ol> <!-- Reverse the order --> <ol reversed> <li>Step 3</li> <li>Step 2</li> <li>Step 1</li> </ol> <!-- Change list type: 1, A, a, I, i --> <ol type="A"> <li>Option A</li> <li>Option B</li> </ol>

3. Definition Lists (<dl>)

For term-definition pairs, like a glossary or FAQ.

<dl> <dt>HTML</dt> <dd>HyperText Markup Language - the standard language for web pages.</dd> <dt>CSS</dt> <dd>Cascading Style Sheets - controls the visual presentation of HTML.</dd> </dl>

🪆 Nested Lists

Lists can contain other lists for hierarchical organization.

<ul> <li>Frontend Development <ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> </ul> </li> <li>Backend Development <ul> <li>Python</li> <li>Node.js</li> <li>PHP</li> </ul> </li> </ul>
💡 Indentation: Always indent nested lists properly. It makes your code readable and helps you spot missing closing tags.

📊 HTML Tables

Tables display tabular data. Never use tables for page layout — that's what CSS is for!

Basic Table Structure

<table> <thead> <tr> <th>Course</th> <th>Duration</th> <th>Level</th> </tr> </thead> <tbody> <tr> <td>HTML Basics</td> <td>2 weeks</td> <td>Beginner</td> </tr> <tr> <td>CSS Styling</td> <td>3 weeks</td> <td>Intermediate</td> </tr> </tbody> </table>

Table Elements Explained

TagPurpose
<table>Container for the entire table
<thead>Groups header rows (semantic, helps screen readers)
<tbody>Groups body rows
<tfoot>Groups footer rows (e.g., totals)
<tr>Table row
<th>Header cell (bold and centered by default)
<td>Standard data cell
<caption>Table title/description

Accessible Table with Caption and Scope

<table> <caption>Monthly Course Enrollment</caption> <thead> <tr> <th scope="col">Month</th> <th scope="col">Students</th> <th scope="col">Completion Rate</th> </tr> </thead> <tbody> <tr> <th scope="row">January</th> <td>150</td> <td>85%</td> </tr> </tbody> </table>
💡 Accessibility: The scope attribute tells screen readers whether a <th> is a column header or row header. This is essential for blind users navigating tables.

✏️ Exercise 6.1: Recipe & Pricing Table

Your Task

Create recipe.html containing:

  1. An <h1> with your favorite recipe name
  2. An unordered list of ingredients (at least 5 items)
  3. An ordered list of cooking steps (at least 4 steps)
  4. A nested list showing recipe variations (e.g., vegetarian option with sub-items)

Then create pricing.html containing:

  1. An accessible table with <caption>, <thead>, <tbody>
  2. Columns: Service, Basic Price, Premium Price
  3. At least 3 rows of services
  4. Proper scope attributes on all header cells

📝 Module 6 Quiz

Test Your Knowledge
1. Which list is best for a set of instructions?
2. What does <dl> stand for?
3. Which tag groups table header rows semantically?
4. What attribute helps screen readers understand table headers?
5. Should you use tables for page layout?

🎯 Module Summary

← Previous Module Next: Module 7 →