Accessible data table markup
Use caption, thead, th scope and a scroll wrapper so screen readers and small screens handle tables well.
- HTML
- GreenSnippets
- MIT
<div role="region" aria-labelledby="sales-caption" tabindex="0" style="overflow-x: auto">
<table>
<caption id="sales-caption">Quarterly sales by region (USD)</caption>
<thead>
<tr>
<th scope="col">Region</th>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Europe</th>
<td>120,000</td>
<td>135,000</td>
</tr>
<tr>
<th scope="row">Asia</th>
<td>98,000</td>
<td>110,500</td>
</tr>
</tbody>
</table>
</div>Example / expected output
<!-- Right-align numeric columns with text-align: end and font-variant-numeric: tabular-nums. -->How it works
A caption names the table, scope on header cells lets assistive technology announce the right header for each data cell, and <thead>/<tbody> give structure. Wide tables should scroll inside a focusable wrapper instead of breaking the page layout. Use tables for tabular data only, never for layout.
This snippet has been reviewed but was not executed by an automated test. Test it in your own environment before relying on it.
Related snippets
- CSS
Respect prefers-reduced-motion
Turn off or shorten animations for users who ask their system for less motion.
- CSS
Accessible focus ring with :focus-visible
Show a clear focus outline for keyboard users without drawing it on mouse clicks.
- HTML
Accessible modal with the dialog element
Use the native dialog element for a modal with built-in focus trapping, Escape to close and a backdrop.
- HTML
Accordion with details and summary
A keyboard-accessible FAQ accordion with no JavaScript, including an exclusive group using the name attribute.

