Summary
Identify which column(s) or row(s) table headers apply to so that users of assistive technologies can understand the context of the data they are reading.
Techniques
-
Ensure that table headers are identified and their scope (row or column) is defined.[[WCAG-1.3.1]]
Examples
In this example, the table shows population change over time. It is split into sections
for each fictional region, so the scope "rowgroup" is applied to each
section heading to associate it with all the cells in the group (each tbody
element defines a new group).
| 1950 | 1975 | 2000 | |
|---|---|---|---|
| Gondor | |||
| Male | 1,001,542 | 1,583,771 | 2,221,945 |
| Female | 1,122,947 | 1,782,371 | 2,544,187 |
| Mordor | |||
| … | |||
<table>
<thead>
<tr>
<th></th>
<th>1950</th>
<th>1975</th>
<th>2000</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="4" scope="rowgroup">Gondor</th>
</tr>
<tr>
<th>Male</th>
<td>1,001,542</td>
<td>1,583,771</td>
<td>2,221,945</td>
</tr>
<tr>
<th>Female</th>
<td>1,122,947</td>
<td>1,782,371</td>
<td>2,544,187</td>
</tr>
</tbody>
<tbody>
<tr>
<th colspan="4" scope="rowgroup">Mordor</th>
</tr>
…
</tbody>
</table>
Explanation
The scope attribute is used to clarify relationships between headers and
cells. It is attached to th elements to clarify their directionality and
takes one of the following four values:
col-
The
colvalue indicates that the header applies to the cells below or above it (dpeending on the directionality of the language).The
colvalue can be used with headers that span multiple columns (i.e., that have acolspanattribute). colgroup-
The
colgroupvalue indicates that the header applies to the cells in the correspondingcolgroupelement definition.The
colgroupvalue must always correspond to acolgroupelement declaration for the table. If acolgroupelement is not defined, the value is invalid. row-
The
rowvalue indicates that the header applies to the cells to the right or left of it (depending on the directionality of the language).The
rowvalue can be used with headers that span multiple rows (i.e., that have arowspanattribute). rowgroup-
The
rowgroupvalue indicates that the header applies to the cells above or below and to the right or left (depending on the directionality of the language) in the group of rows the header belongs to.A row group is defined by the
thead,tbody, ortfootthat the header is within. If none of these elements are specified, the attribute value is invalid.
Although it is not necessary to specify a scope for simple tables where the first row(s) or column(s) contain the header cells, it is best to specify the scope whenever there is an ambiguity.
If a table is divided into sections, for example, the header rows for each section might be read out for each cell if a row group is not properly defined (see Example 1.
If you do not declare a scope information where these ambiguities exist, assistive technologies will make a best guess at how to apply the headers, which can lead to incorrect interpretations.
Note
Some guidance states that col and row scopes cannot be used when
colspan and rowspan attributes are declared; that you must define
colgroup and rowgroup scopes with the applicable structuring requirements.
This advice is incorrect.
Related Links
- MDN — <table>: The Table element
- HTML — The
tableelement