CHAPTER 29 · HTML
Accessible tables: clear header relationships and usable small-screen views
Help people understand a table when they use a small screen, keyboard or screen reader. Start with simple relationships, learn explicit header references when needed, and make a wide table scroll without hiding its data.
Download example files (ZIP)Ask what each value means
Explicit links between a cell and its headers
<th id="planned" scope="col">Planned examples</th>
<th id="lists-topic" scope="row">Lists</th>
<td headers="lists-topic planned">4</td>Complete program: named-table-headers.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Read Each Practice Count in Context</title>
</head>
<body>
<h1>Connect every count with its labels</h1>
<table>
<caption>Practice counts with explicit header references</caption>
<thead>
<tr>
<th id="topic-column" scope="col">Topic</th>
<th id="planned-column" scope="col">Planned examples</th>
<th id="checked-column" scope="col">Checked examples</th>
</tr>
</thead>
<tbody>
<tr>
<th id="lists-row" scope="row">Lists</th>
<td headers="lists-row planned-column">4</td>
<td headers="lists-row checked-column">3</td>
</tr>
<tr>
<th id="links-row" scope="row">Links</th>
<td headers="links-row planned-column">3</td>
<td headers="links-row checked-column">3</td>
</tr>
</tbody>
</table>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
A caption and a description are different
Give a wide table its own scrolling space
- 1Caption: name the table
- 2Headers: explain each value
- 3Scroll container: preserve wide content
- 4Keyboard focus: reach and operate that container
Explicit headers values refer to th ids without a #. Check the experience instead of relying on appearance alone.
Complete program: small-screen-table.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>A Scrollable Practice Timetable</title>
<style>
.table-window { overflow-x: auto; max-width: 100%; }
.table-window:focus-visible { outline: 3px solid #31573d; outline-offset: 3px; }
table { border-collapse: collapse; min-width: 560px; }
th, td { border: 1px solid #687466; padding: 10px; text-align: left; }
</style>
</head>
<body>
<h1>Read all the timetable columns</h1>
<p id="table-help">On a narrow screen, scroll the table sideways. Keyboard users can focus its container and use the arrow keys.</p>
<div class="table-window" tabindex="0" role="region" aria-labelledby="plan-caption" aria-describedby="table-help">
<table>
<caption id="plan-caption">Practice sessions and preparation</caption>
<thead>
<tr><th scope="col">Session</th><th scope="col">Room</th><th scope="col">Start</th><th scope="col">Bring</th></tr>
</thead>
<tbody>
<tr><th scope="row">HTML notice</th><td>Room 6</td><td>10 am IST</td><td>Notebook and saved example</td></tr>
<tr><th scope="row">Link practice</th><td>Room 8</td><td>11 am IST</td><td>Two linked HTML files</td></tr>
</tbody>
</table>
</div>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Explain the wrapper's attributes
What to check manually
Problem and solution: the last column cannot be reached
Common mistakes and useful tips
Using headers="#planned" rather than an id value without #. Referring to an id on a paragraph instead of a th in the same table. Renaming header ids without updating dependent cells. Adding role="grid" without implementing grid keyboard behaviour. Hiding columns or shrinking all text to avoid scrolling. Making every ordinary cell a tab stop. Claiming an accessibility audit based only on visual alignment.
Practice questions
What information does headers="lists-row planned-column" supply? Does headers visibly print those labels inside the cell? When might splitting a complex table be better than adding more header references? What does overflow-x: auto do? Why give the scroll container a focus route and visible outline? Test small-screen-table.html at a narrow width. Reach its last column with a pointer and keyboard, then trace every headers reference in the first program to a matching th.
Check your practice answers
It explicitly identifies the header cells that label that data cell. No. It describes associations for tools; the visible value stays the same. When simpler separate tables express the information more clearly and are easier to maintain and navigate. It allows horizontal scrolling when content exceeds the container's width. Keyboard users need a way to reach and operate the overflowing area and see where focus is. Reduce the browser width until scrolling is needed. Check that Bring remains reachable. In the first program, each referenced id must identify the intended th within the same table.
Interview questions
When would you use headers instead of relying only on scope?
Does a responsive table have to hide columns?
Why is a native table different from an ARIA grid?
Does adding ARIA guarantee accessibility?
Quick revision
Keep native table meaning and simple headers where possible. Explicit headers values refer to th ids in the same table. A wide table can scroll without losing columns. Test focus, reading order and access to the final column.