Tables
Accessible tables and media ensure that all users, including those using assistive technologies, can understand, navigate, and operate your content. For tables, use semantic structure to expose relationships between headers and data. For media, always provide user controls and alternatives like captions or transcripts.
Examplesβ
β Correct
<table>
<caption>Quarterly Sales Report</caption>
<thead>
<tr>
<th scope="col">Quarter</th>
<th scope="col">Product A</th>
<th scope="col">Product B</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Q1</th>
<td>120</td>
<td>90</td>
<td>210</td>
</tr>
<tr>
<th scope="row">Q2</th>
<td>150</td>
<td>110</td>
<td>260</td>
</tr>
</tbody>
</table>
β Incorrect
<table border="1">
<tr>
<td colspan="4">Quarterly Sales Report</td>
</tr>
<tr style="background: green;">
<td>Q1</td>
<td>120</td>
<td>90</td>
<td>210</td>
</tr>
<tr style="background: red;">
<td>Q2</td>
<td>150</td>
<td>110</td>
<td>260</td>
</tr>
</table>
π Do'sβ
- Use
<table>only for tabular data, never for layout. - Mark header cells with
<th>and usescope(e.g.,col,row,colgroup,rowgroup) orheaders/idfor complex tables. - Make tables responsive without breaking semantics; consider stacked views with ARIA labels.
π Don'tsβ
- Use tables for page layout or grid structures.
- Fail to mark header cells as
<th>or omitscope. - Omit captions (loss of context) or merge cells without defining relationships.
- Use color alone to communicate status/meaning.
- Use autoplay with sound for audio/video.
- Provide media without controls.
- Publish media without captions or a transcript.
Extrasβ
- Multi-level/complex tables:
- Use
scopewhere possible; otherwise useidon headers andheaderson data cells for explicit associations.
- Use
- Responsiveness:
- Donβt break semantics; reposition visually with CSS while preserving
<th>/<td>relationships. Use ARIA labels for stacked views.
- Donβt break semantics; reposition visually with CSS while preserving
Links/Sources/Plugins/Toolsβ
- WCAG 2.2 Overview: https://www.w3.org/TR/WCAG22/
- WCAG 1.3.1 (Info and relationships β tables): https://www.w3.org/WAI/WCAG22/quickref/#info-and-relationships
- MDN HTML Tables: https://developer.mozilla.org/docs/Learn/HTML/Tables
- WAI Tutorials β Tables: https://www.w3.org/WAI/tutorials/tables/