Lists and tables
Lists and tables organise information so it's easy to scan. Navigation menus, shopping lists, step-by-step instructions and price comparisons are all built with them.
Unordered lists
Use <ul> when order doesn't matter. Each item is an <li> (list item).
Ordered lists
Use <ol> when the sequence matters: steps, rankings, instructions.
Nested lists
Put a whole new list inside an <li>:
Description lists
For term–definition pairs, like glossaries or FAQs:
Navigation menus are usually a
<ul>of links inside a<nav>. CSS then lays them out horizontally.
Tables
Tables are for tabular data: information with rows and columns. They're not for page layout (that was a 1990s hack; we use CSS now).
| Element | Meaning |
|---|---|
<table> |
The table |
<caption> |
Its title (helps accessibility) |
<thead>, <tbody>, <tfoot> |
Header, body and footer row groups |
<tr> |
A table row |
<th> |
A header cell (bold and centred by default) |
<td> |
A data cell |
(border="1" is just to make the lines visible here. In real projects, style borders with CSS.)
Spanning rows and columns
scope="col" and scope="row" tell screen readers which cells a header describes.
Practice
Build a weekly timetable table with days as columns and 3 time slots as rows, using <thead>, <tbody> and at least one colspan. Then add an ordered list of your 3 study goals below it.
1.Which list should you use for recipe steps?
2.Should you use tables to lay out a page's columns?