HTML chapters

Chapter 10 of 17

Tables for related records

Try this in our HTML Compiler →

The idea

Use a table when data has row and column relationships, not to position a page. A caption names the dataset, th identifies a header, and scope associates that header with a row or column. Lists are better when there are no comparable columns.

Worked example

<table>
  <caption>Study sessions</caption>
  <tr><th scope="col">Topic</th><th scope="col">Minutes</th></tr>
  <tr><td>HTML</td><td>20</td></tr>
  <tr><td>CSS</td><td>25</td></tr>
</table>

What to check

The two columns mean the same thing for each record. A screen reader can use the headers to interpret a data cell.

Practice task

Add a JavaScript row. Keep the minutes as data; do not use the table to lay out buttons.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on