
Accessible Data Tables: Headers, Captions, Responsive
A real <table>, a <caption>, and <th scope> get you most of the way. Add headers/id for complex tables, aria-sort for sortable headers, and one canonical responsive pattern that survives small screens.
TL;DR: Accessible data tables come down to three things — a real <table> element, a <caption> and <th> with scope (or headers/id for complex tables), and a responsive pattern that does not destroy header-cell association at small widths. WCAG 2.1 SC 1.3.1 Info and Relationships and SC 1.3.2 Meaningful Sequence are the load-bearing criteria. This guide covers when to use a table, the semantic baseline we recommend for every table, the headers/id pattern for merged cells, sortable and selectable rows, three responsive patterns that work, and the audit criteria to apply to your own templates as a first-phase scope.
When to use <table> and when not to
A table is the right element when each cell sits at the intersection of headers that describe it — rows and columns where removing the row or column structure would make the data meaningless. A revenue-by-quarter report is a table. A directory of staff with name, role, and email columns is a table. A comparison of plan tiers with feature rows is a table.
A table is not for layout. CSS layout replaced table-based layout long ago, and flexbox and grid have since removed any remaining reason for it, but the anti-pattern still appears in legacy systems and email templates. Layout tables can confuse screen readers — a screen reader has to guess whether a table holds data, and when it guesses wrong it announces row and column counts for content that has none — and they work against responsive design. If the only purpose of the structure is visual alignment, the answer is grid or flexbox, not <table>.
Card lists, key-value pairs, and definition lists are also not tables. A staff directory rendered as cards with name and role is a card list (<ul> or <section>). A property list (label–value, label–value) is a definition list (<dl>). The decision rule is operational: if removing the row or column structure would destroy the meaning, it is a table; if the structure is purely visual, it is something else.
The semantic baseline for every data table
Four pieces form the semantic baseline we recommend for every data table.
<table>
<caption>Quarterly revenue by region, FY2025</caption>
<thead>
<tr>
<th scope="col">Region</th>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
<th scope="col">Q3</th>
<th scope="col">Q4</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">North America</th>
<td>$4.2M</td>
<td>$4.5M</td>
<td>$4.9M</td>
<td>$5.1M</td>
</tr>
<tr>
<th scope="row">EMEA</th>
<td>$3.1M</td>
<td>$3.4M</td>
<td>$3.6M</td>
<td>$3.8M</td>
</tr>
</tbody>
</table>The outer element is <table>. Never <div role="table"> when a real table works — the W3C ARIA Authoring Practices advise using the native HTML element whenever one has equivalent semantics, and the ARIA version has to recreate every row, header, and cell role by hand.
<caption> is the first child of <table>. It describes the table to all users, and the W3C WAI Tables Tutorial notes that most screen readers announce the content of captions. Visual designers sometimes replace the caption with a heading above the table; that satisfies visual hierarchy but leaves the table without a programmatic name. WCAG does not require a caption on every table, but <caption> is the documented technique (H39) for tying a title to a table under SC 1.3.1 Info and Relationships, and it is how screen reader users identify a table in table navigation.
<thead>, <tbody>, and <tfoot> group the rows structurally. They do not add accessibility on their own — header association comes from <th> and scope — but they let CSS target header rows separately from body rows without brittle nth-child selectors.
<th> elements with scope="col" on column headers and scope="row" on row headers establish the cell-to-header relationship programmatically. This is the SC 1.3.1 contract for simple two-axis tables — a screen reader on any cell can announce both its column and its row context. Without scope, screen readers fall back to inference, which is inconsistent across products.
The W3C WAI Tables Tutorial is the authoritative reference for this baseline; it includes worked examples for one-header, two-header, irregular, and multi-level tables, plus captions and summaries.
Complex tables — merged cells, multi-level headers, headers/id
scope works for simple two-axis tables, and with scope="colgroup" or scope="rowgroup" it also covers a header that spans several columns or rows (e.g., "2024" spanning four quarter sub-headers), provided the group is defined in the markup: a <colgroup> for the columns, or a <thead>, <tbody>, or <tfoot> for the rows. It stops working when column headers change part-way through the table, or when three or more header cells describe each data cell.
For these cases, use the headers attribute on <td> and <th> referencing one or more id values on header cells:
<table>
<caption>Revenue by region and product line, FY2025</caption>
<col>
<colgroup span="2"></colgroup>
<colgroup span="2"></colgroup>
<thead>
<tr>
<td rowspan="2"></td>
<th id="hw" colspan="2" scope="colgroup">Hardware</th>
<th id="sw" colspan="2" scope="colgroup">Software</th>
</tr>
<tr>
<th id="hw-units" headers="hw" scope="col">Units</th>
<th id="hw-rev" headers="hw" scope="col">Revenue</th>
<th id="sw-licenses" headers="sw" scope="col">Licenses</th>
<th id="sw-rev" headers="sw" scope="col">Revenue</th>
</tr>
</thead>
<tbody>
<tr>
<th id="na" scope="row">North America</th>
<td headers="na hw hw-units">12,400</td>
<td headers="na hw hw-rev">$4.2M</td>
<td headers="na sw sw-licenses">8,900</td>
<td headers="na sw sw-rev">$3.1M</td>
</tr>
</tbody>
</table>Each <td> lists every relevant header by id. Listing them from the outermost header inward is a readable convention, but the HTML specification treats the list as an unordered set, so do not rely on the order to control what a screen reader announces first. This is verbose and harder to maintain than scope, but it is the mechanism W3C documents for tables whose header relationships are too complex for scope.
When the data permits, the better answer is to split a complex table into two simple tables — one for hardware, one for software in the example above. Two simple tables with scope are easier to maintain, easier to test, and announced more consistently than a single multi-level table with headers/id. Reach for the split first; reach for headers/id only when the comparison must happen in a single visual structure.
Sortable, filterable, and selectable tables
Sort controls go on the <th> as a button child. The current sort state is communicated by aria-sort on the <th> itself, which takes one of four values: ascending, descending, none, or other.
<th scope="col" aria-sort="ascending">
<button type="button">
Region
<span aria-hidden="true">▲</span>
</button>
</th>The button text should include the column name; the current sort state comes from aria-sort on the <th>. A triangle icon alone fails — screen reader users cannot tell which direction is current without aria-sort or visually hidden text. The W3C sortable table example conveys state with aria-sort and hides the icon from assistive technology; visually hidden text adds a fallback, but test with your target screen readers so the state is not announced twice.
Filter controls usually live above the table, not in headers. Each filter should announce its effect on the result count, for example through an aria-live region near the table:
<div aria-live="polite" aria-atomic="true" class="sr-only">
Showing 24 of 142 results.
</div>The aria-live="polite" queue announces changes after the current screen reader utterance finishes, so users hear the new count without losing the input they were typing.
Selectable rows use a checkbox in the first cell of each row, with a "select all" checkbox in the corresponding <th>. Each row checkbox needs an accessible name — aria-labelledby pointing to the row's identifying cell is the cleanest pattern:
<tr>
<td>
<input type="checkbox" id="sel-na" aria-labelledby="region-na" />
</td>
<th id="region-na" scope="row">North America</th>
<td>$17.7M</td>
</tr>ARIA grid (role="grid") turns a table into a composite widget: only one focusable element inside it is in the page tab sequence, and arrow keys move focus between cells. A data table that users only read does not need it. For interactive tables the W3C sources point in different directions. WAI-ARIA 1.2 says that if a tabular container maintains a selection state, provides its own two-dimensional navigation, or allows the user to rearrange or otherwise manipulate its contents or the display thereof, authors SHOULD use grid or treegrid instead; the W3C sortable table example keeps a native <table> with aria-sort. A grid can dramatically shorten the page tab sequence when a table holds many interactive elements, but the author has to provide the code that manages focus movement inside it — see the APG Grid pattern for the details.
The responsive table problem and three patterns that solve it
The hardest problem with data tables is not the markup — it is the small-screen experience. A 12-column financial report is unusable at 360px. There are three patterns that work, plus a newer one worth knowing.
The first is horizontal scroll: wrap the table in an overflow-x: auto container. Markup stays untouched, screen reader semantics are preserved, and the desktop experience is unchanged. The cost is poor mobile UX — users zoom and scroll horizontally through wide data, which is hard on touch and easy to lose place in. Make the scroll container keyboard-reachable with tabindex="0" so keyboard users can scroll without a pointing device, and give it a visible focus indicator so they can see what is focused.
The second is stacked rows: at small viewports, each row collapses into a card with cell labels. Adrian Roselli's responsive accessible table is a widely cited worked example. The trick is preserving the header–cell association — each cell shows its header label through a ::before pseudo-element. The simplest version reads the label from a data-label attribute on each <td>; Roselli generates the labels from the header cells with a short script instead, because hand-maintained attributes can drift out of sync with the headers:
<table class="responsive-table">
<caption>Quarterly revenue by region, FY2025</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">North America</th>
<td data-label="Q1">$4.2M</td>
<td data-label="Q2">$4.5M</td>
</tr>
</tbody>
</table>
<style>
@media (max-width: 600px) {
.responsive-table thead { display: none; }
.responsive-table tr {
display: block;
border: 1px solid #ddd;
margin-bottom: 1rem;
padding: 0.75rem;
}
.responsive-table td {
display: block;
}
.responsive-table td::before {
content: attr(data-label) ": ";
font-weight: 600;
}
}
</style>Critically, the display: block on rows and cells does not strip the underlying <table> semantics from the accessibility tree in current browsers — but before Chrome 80 (2020) and Safari 17 (2023), browsers stripped them when display was changed (per Adrian Roselli's browser testing, updated October 7, 2023). Add role="table", role="rowgroup", role="row", role="columnheader", role="rowheader", and role="cell" explicitly if you need to support Safari versions before 17, then test with VoiceOver to confirm the behavior on the targets you actually ship to.
The third is priority-plus: show essential columns at narrow widths, progressively reveal more as the viewport widens. This requires a column-priority system at the data layer — every column carries a priority — for example, from 1 (always visible) to 4 (visible only at desktop). At narrow widths, low-priority columns are hidden behind a "show more" disclosure or removed entirely. Priority-plus keeps the table semantically intact at every breakpoint but trades data completeness for layout simplicity.
A newer option worth knowing is the container query approach. With CSS @container, the table can adapt to its container width rather than the viewport width, which works in compound layouts where the table sits inside a sidebar or split pane. Size container queries have been Baseline across major browsers since February 2023.
Common mistakes that fail audits
The patterns below are common reasons tables fail accessibility review.
| Mistake | Why it fails | Fix |
|---|---|---|
| `` instead of `` | Native semantics come free; ARIA must be added and maintained per cell | Use a real `` |
| Heading above the table replacing `` | Table has no programmatic name | Add `` as first child of `` |
| `scope` alone on a table whose headers change mid-table or stack three deep | `scope` cannot express those relationships | Use `headers`/`id` or split into two simple tables |
| Sort indicator as icon only | Screen reader users do not hear current sort state | Add `aria-sort` on the `` and hide the icon from assistive technology |
| `display: block` on cells with no visible header labels | Sighted users lose the column context, and older browsers (before Safari 17) also dropped table semantics | Add `data-label` + `::before` pattern, retest with VoiceOver |
| Empty `` used for the blank corner cell | A header cell with no text provides no header for its cells, and checkers such as axe-core flag it (best-practice rule `empty-table-header`) | Leave the corner cell as an empty ``; give every real header visible text |
The sort state on sortable headers is worth calling out separately — an icon-only version looks cleaner, so it is easy to ship and then patch after an audit flags it. Building aria-sort and the hidden icon into the design system component template prevents the regression.
Audit criteria for your tables
On template-driven sites, tables tend to be concentrated in a few templates — admin dashboards, analytics views, financial reports, comparison pages — so an audit pays back across many pages once the templates are fixed.
- Inventory every data table on the site. Start with the top 10 templates by traffic
- Confirm every table has a
<caption>as the first child of<table> - Verify
scopeorheaders/idon every<th> - Open each table with a screen reader (NVDA Browse mode on Windows, VoiceOver on macOS) and confirm cell announcements include the right column and row headers
- Test horizontal scroll regions for keyboard reachability —
tabindex="0"on the scroll container with a visible focus indicator - On mobile, confirm any responsive transformation still preserves header–cell relationships. The
<table>element on MDN documents the caption, scope, and headers/id requirements to check against - Add automated table accessibility checks to CI alongside visual regression tests — CSS changes can break header association without changing how the table looks, so screenshots alone will not catch them
If a check fails, the fix is at the template or component level — table accessibility is not a per-page problem. Update the design system table component, then re-run the audit across the templates that use it.
The semantic baseline plus one responsive pattern applied consistently covers the core of what table audits check.