7 / 10 · Intro
Tables
A bus timetable is a table: every cell only makes sense together with its row heading and its column heading.
Jump to the 10 practice questions1Explain
Rows, cells and headers
A table is built row by row. <table> wraps everything, each <tr> (table row) is one row, and inside a row each <td> (table data) is one cell. Cells that label a row or a column use <th> (table header) instead, which browsers show in bold and centre by default. The number of cells in each row should match, so the columns line up.
<table>
<caption>Bread prices, October 2026</caption>
<thead>
<tr><th scope="col">Loaf</th><th scope="col">Weight</th><th scope="col">Price</th></tr>
</thead>
<tbody>
<tr><th scope="row">Sourdough</th><td>800 g</td><td>6.50</td></tr>
<tr><th scope="row">Rye</th><td>600 g</td><td>5.00</td></tr>
</tbody>
</table>2Problem
One row
Hint
Short for table row.
Solution
Answer: tr
tr, table row.
3Problem
A column label
Which element labels a column?
Hint
Header cells use a different element from data cells.
Solution
Answer: th
th is a header cell; td holds data.
4Explain
Make the table explain itself
Three additions turn a grid of cells into a table that everyone can read. First, <caption>, placed right after the opening <table> tag, gives the table a title; screen readers announce it before the contents, so the listener knows what the table is about. Second, the scope attribute on each <th> says whether it labels a column (scope="col") or a row (scope="row").
<table border="1">
<caption>Opening hours</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">Open</th><th scope="col">Close</th></tr>
</thead>
<tbody>
<tr><th scope="row">Monday</th><td>7:00</td><td>18:00</td></tr>
<tr><th scope="row">Sunday</th><td>Closed</td><td>Closed</td></tr>
</tbody>
</table>5Problem
scope="row"
What does scope="row" on a th mean?
Hint
The header labels the cells beside it in the same row.
Solution
Answer: It labels the cells in its row
scope tells assistive technology which cells a header describes.
6Explain
Example: from a list of facts to a table
The bakery delivers to the north of town on Tuesdays and to the south on Thursdays. Turn these two facts into a table.
- Decide what one row is: one area. Two areas give two body rows.
- Decide what the columns are: the area and the delivery day. Their names go in a header row of th cells with scope="col".
- The area names label their rows, so they are th with scope="row"; the days are data, so they are td.
- Every row has 2 cells, so the columns line up. caption, right after the opening table tag, names the table.
<table border="1">
<caption>Delivery days</caption>
<thead>
<tr><th scope="col">Area</th><th scope="col">Day</th></tr>
</thead>
<tbody>
<tr><th scope="row">North</th><td>Tuesday</td></tr>
<tr><th scope="row">South</th><td>Thursday</td></tr>
</tbody>
</table>7Problem
Where the caption goes
Where is caption written?
Hint
Screen readers announce it before the contents.
Solution
Answer: Right after the opening table tag
caption is the first child of table, so the title comes before the rows.
8Explore
Cells that span
A cell can stretch across several columns with colspan or several rows with rowspan. In a weekly timetable, a lunch break that covers all five weekdays can be one cell with colspan="5". When a cell spans, the row it sits in needs fewer cells: if a row normally has 6 cells and one of them has colspan="5", that row contains only 2 cells in the HTML.
A cell with colspan="3" takes the room of three cells, so that row needs fewer td elements.
Tap a choice: the code and the preview change together.
<table border="1">
<tr><th>Mon</th><th>Tue</th><th>Wed</th></tr>
<tr><td>Lunch</td><td>Lunch</td><td>Lunch</td></tr>
</table>Nothing is drawn: there is no visible content.
9Problem
How many cells are written?
A row normally has 6 cells. One cell has colspan="4". How many cells are written in that row?
Hint
One cell covers 4 of the 6 places.
Solution
Answer: 3
The spanning cell takes the place of 4, so 6 minus 4 plus 1 is 3 cells.
10Problem
After a rowspan
A table has 3 columns. In row 2, the first cell has rowspan="2". How many cells are written in row 3?
Hint
The cell from row 2 also fills one place in row 3.
Solution
Answer: 2
rowspan="2" stretches the cell down into row 3, so row 3 has only 3 − 1 = 2 places left to write.
11Problem
A table for layout?
Someone uses a table only to place a photo to the left of some text. Is that a good use?
Hint
Think of a screen reader announcing rows and columns.
Solution
Answer: No: tables are for data; use CSS for layout
A table tells assistive technology that the content is data in rows and columns. For placing things side by side, CSS is the tool.
12Practice
Caption, thead and tbody
Add a <caption> that says Opening hours. Move the first row into a <thead>, make its cells <th scope="col">, and put the other rows in a <tbody>.
- caption
- 3 column headers in thead
- 3 rows in tbody
<table>
<tr><td>Day</td><td>Open</td><td>Close</td></tr>
<tr><td>Monday</td><td>7:00</td><td>18:00</td></tr>
<tr><td>Saturday</td><td>8:00</td><td>14:00</td></tr>
<tr><td>Sunday</td><td>Closed</td><td>Closed</td></tr>
</table>Hint
caption comes right after <table>. The first row moves into thead, the others into tbody.
A solution
<table>
<caption>Opening hours</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">Open</th><th scope="col">Close</th></tr>
</thead>
<tbody>
<tr><td>Monday</td><td>7:00</td><td>18:00</td></tr>
<tr><td>Saturday</td><td>8:00</td><td>14:00</td></tr>
<tr><td>Sunday</td><td>Closed</td><td>Closed</td></tr>
</tbody>
</table>13Practice
One lunch cell
The lunch break is the same on every day. Replace the three Lunch cells with one cell that spans 3 columns.
- colspan="3" cell
- only one Lunch cell
<table>
<tr><th scope="col">Time</th><th scope="col">Mon</th><th scope="col">Tue</th><th scope="col">Wed</th></tr>
<tr><th scope="row">9:00</th><td>Maths</td><td>Art</td><td>Music</td></tr>
<tr><th scope="row">12:00</th><td>Lunch</td><td>Lunch</td><td>Lunch</td></tr>
</table>Hint
Keep the 12:00 header and write a single td with colspan="3".
A solution
<table>
<tr><th scope="col">Time</th><th scope="col">Mon</th><th scope="col">Tue</th><th scope="col">Wed</th></tr>
<tr><th scope="row">9:00</th><td>Maths</td><td>Art</td><td>Music</td></tr>
<tr><th scope="row">12:00</th><td colspan="3">Lunch</td></tr>
</table>14Explain
Common mistakes
<table border="1">
<tr><td><b>Day</b></td><td><b>Open</b></td></tr>
<tr><td>Monday</td><td>7:00</td></tr>
</table><table border="1">
<tr><th scope="col">Day</th><th scope="col">Open</th></tr>
<tr><td>Monday</td><td>7:00</td></tr>
</table>Bold cells only look like headers. A screen reader cannot tell which cell labels which; th with scope says it.
15
Summary
- Tables are for data: table, tr, th, td.
- caption names the table; scope ties headers to cells; thead, tbody, tfoot group rows.
- colspan and rowspan merge cells; keep tables simple.