Semantics and accessibility
Data tables
Goal: Build accessible data tables · 9 min
Tables are for tabular data (timetables, price lists) — never for page layout.
<table>
<caption>Opening hours</caption>
<thead><tr><th scope="col">Day</th><th scope="col">Hours</th></tr></thead>
<tbody><tr><th scope="row">Mon</th><td>9–17</td></tr></tbody>
</table>
<tr>row,<td>data cell,<th>header cellscope="col"/scope="row"tells screen readers which cells a header describes<caption>names the table;<thead>,<tbody>,<tfoot>group rowscolspan/rowspanmerge cells
Worked example: A small price table
- caption describes the content.
- Header row with scope="col".
- Each product name is a row header.
<table>
<caption>Prices</caption>
<thead><tr><th scope="col">Item</th><th scope="col">Price</th></tr></thead>
<tbody>
<tr><th scope="row">Coffee</th><td>2.50 €</td></tr>
<tr><th scope="row">Tea</th><td>2.00 €</td></tr>
</tbody>
</table>