A table that looks clear to your eyes may be a puzzle to someone listening to it through a screen reader. Three small additions turn a grid of cells into a table anyone can understand: headers, a caption and scope.
Use th for every header#
Any cell that labels other cells must be a <th>, not a <td>. Screen readers use <th> cells to announce context. When a user lands on the cell "220", the reader can say "Latte, Price, 220" because it knows which headers apply.
Headers can run across the top (column headers) and down the left side (row headers). Both are <th>.
Caption: the title of the table#
<caption> gives the table a visible title. It must be the first child of <table>:
<table>
<caption>Brew and Byte prices by drink and size (Rs.)</caption>
<tr>
<th></th>
<th>Small</th>
<th>Medium</th>
<th>Large</th>
</tr>
<tr>
<th>Latte</th>
<td>180</td>
<td>220</td>
<td>260</td>
</tr>
<tr>
<th>Mocha</th>
<td>200</td>
<td>240</td>
<td>280</td>
</tr>
</table>A caption is better than a heading placed above the table, because it is programmatically linked to it. Assistive technology can announce "Table: Brew and Byte prices by drink and size" when the user reaches it.
scope: say which direction a header applies#
The scope attribute on a <th> tells software whether the header labels a column or a row.
<table>
<caption>Weekly workshop schedule</caption>
<tr>
<td></td>
<th scope="col">Morning</th>
<th scope="col">Afternoon</th>
</tr>
<tr>
<th scope="row">Monday</th>
<td>Latte art</td>
<td>Cupping</td>
</tr>
<tr>
<th scope="row">Tuesday</th>
<td>Barista basics</td>
<td>Closed</td>
</tr>
</table>| Value | Meaning |
|---|---|
col | This header labels the cells below it |
row | This header labels the cells to its right |
colgroup and rowgroup | Labels a group of columns or rows |
For simple tables, browsers can guess the direction, but explicit scope is more reliable and costs only a few characters.
The empty corner cell#
In a table with both column and row headers, the top-left corner has nothing to label. Leave it as an empty <td> (as in the example above) or give it text such as "Day", which is clearer to everyone.
Complex headers#
Tables with several levels of headers can use the id and headers attributes: each <td> lists the ids of its headers. That is rarely needed. If you find yourself reaching for it, consider splitting the data into two simpler tables, which is easier for everyone.
Common mistakes#
- Making header cells
tdand only styling them bold. - Placing
<caption>anywhere except directly after the opening<table>tag. - Leaving
scopeoff tables that have both row and column headers. - Creating "title" rows using a single cell with the table title inside. Use
caption. - Using empty
thcells without any alternative text for people who need it.
Try it yourself#
Create a table of your own weekly study plan with days down the left and time slots across the top. Add a caption, use th with proper scope values, and leave the top-left cell empty or labelled. If you have a screen reader, move through the table cell by cell and listen to how headers are announced.
Recap#
Use th for all headers, caption as the first child to title the table, and scope="col" or scope="row" to say what each header labels. These small details make tables meaningful to assistive technology.
Check your understanding
Lesson quiz
OptionalA short quiz to check what you just learned.
- Questions
- 3
- Time limit
- 5 min
- Pass mark
- 70%
- Best score
- -