
When a user cannot see the visual indicators of headers in tables a screen reader will speak which headers are associated with a particular data cell.
The th element is used to specify which elements are the header elements of a table. Columns and rows can have headers.
The following example has been copied from the WebAIM.org - Creating Accessible Tables (Opens in new window) site.
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Birthday</th>
</tr>
<tr>
<th>Jackie</th>
<td>5</td>
<td>April 5</td>
</tr>
<tr>
<th>Beth</th>
<td>8</td>
<td>January 14</td>
</tr>
</table>
| Name | Age | Birthday |
|---|---|---|
| Jackie | 5 | April 5 |
| Beth | 8 | January 14 |
With this technique screen readers will specify the headers associated with a particular data cell. It is used when more than one row and/or column header is associated with a particular cell.
The following code demonstrates the potential requirement for two logical levels of headers. It uses:
In this example id attribute uniquely identifies an element for referral by the headers attribute.
This technique also associates th elements with data cells.
The values of the headers attribute are the ids of the associated th tags.
The following example has been copied from the WebAIM.org - Creating Accessible Tables (Opens in new window) site.
<table>
<tr>
<th id="name">Name</th>
<th id="age">Age</th>
<th id="birthday">Date</th>
</tr>
<tr>
<th rowspan="2" id="birth">by birth</th>
<th id="jackie">Jackie</th>
<td headers="birth jackie age">5</td>
<td headers="birth jackie birthday">April 5</td>
</tr>
<tr>
<th id="beth">Beth</th>
<td headers="birth beth age">8</td>
<td headers="birth beth birthday">January 14</td>
</tr>
<tr>
<th id="step">by marriage</th>
<th id="jenny">Jenny</th>
<td headers="step jenny age">12</td>
<td headers="step jenny birthday">Feb 12</td>
</tr>
</table>
| Name | Age | Age | |
|---|---|---|---|
| by birth | Jackie | 5 | April 5 |
| Beth | 8 | January 14 | |
| by marriage | Jenny | 12 | Feb 12 |