A table is for tabular data. That is a grid where each row shares the same columns, and where each column has a heading.
The accessibility of a table depends almost entirely on how you mark up its headers, and on the fact that you use a table at all and not a set of divs.
The previous lesson in this module covered "What Are the Three List Types and When Is Each Right?", and this lesson is the last one in the HTML Elements and Tags module.
What is the structure of a table?
<table>
<caption>Monthly signups for 2026</caption>
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Signups</th>
<th scope="col">Trials</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">January</th>
<td>1,204</td>
<td>318</td>
</tr>
<tr>
<th scope="row">February</th>
<td>1,388</td>
<td>402</td>
</tr>
</tbody>
</table>There are four elements that carry the meaning. The <caption> names the table, and it is announced when a screen reader reaches it. The <thead> holds the header row, the <tbody> holds the rows of data, and the scope attribute on each header says which cells it labels.
Why does the scope matter?
Without it, a screen reader that is reading a data cell has no way to know what the number means. Is the 1,204 the signups or the trials?
With the scope="col" on the header, the association is explicit. That header labels the cells below it.
The scope="row" does the same for a row, and it lets the first column act as a label for the rest of the row.
<tr>
<th scope="row">January</th> <!-- this cell labels its row -->
<td>1,204</td>
<td>318</td>
</tr>For a more complex table, where a header spans several columns or rows, the rowspan and the colspan describe the shape, and the headers that apply to a cell are given with the headers attribute that lists their ids.
<th id="region" colspan="2">Region</th>
...
<td headers="region quarter">412</td>How do you style a table without losing its structure?
The important rule is that you change only the presentation. A striped row, a border, a wider first column, all of them are fine.
What breaks the table is styling the cells as if they were a grid of separate boxes. The rounded corners and the gaps on individual cells make the table read as a set of disconnected tiles rather than as a grid, and that is worse than no styling at all.
/* a legible, boring table */
table {
width: 100%;
border-collapse: collapse;
font-variant-numeric: tabular-nums;
}
th, td {
padding: 0.75rem 1rem;
text-align: left;
border-bottom: 1px solid #e2e2e2;
}
thead th {
border-bottom: 2px solid #333;
}
tbody tr:hover {
background: #f7f7f7;
}There are two details that are easy to miss.
The border-collapse: collapse gives you a single clean line between the cells instead of doubled borders.
And the font-variant-numeric: tabular-nums makes the digits the same width, so the numbers line up in the column.
When is a table the wrong tool?
There are two cases that come up constantly.
A layout table, which is a grid of boxes used to position the content, should be CSS and not a table. The modern approach with flexbox or grid is more robust, and a layout table announces meaningless column headers to a screen reader.
And a table used for a list of items, where there is only one column of real data, is usually a list, with the visual table appearance done in the CSS.
<!-- a table used only to arrange boxes -->
<table><tr><td>sidebar</td><td>content</td></tr></table>
<!-- the same thing, as a layout -->
<div class="page">
<aside>sidebar</aside>
<main>content</main>
</div>If a table has no headers at all and no real tabular data, then it is a layout table.
You reach for the CSS grid instead, and the semantics improve for free.
How do the tables behave on a phone?
A wide table does not fit a narrow screen, and the usual solutions are these. You let the table scroll inside a wrapper, you reduce the number of columns on small screens, or you restyle each row as a stacked card.
The wrapper approach is the most robust and it takes the least code.
<div class="table-scroll" tabindex="0" role="region" aria-label="Monthly signups">
<table>...</table>
</div>The tabindex and the labelled region are not decoration. A scrollable area that cannot be focused is unreachable by the keyboard, and a screen reader user needs to know what they are scrolling.
Where does the caption go, and why does it matter?
The caption can be the first or the last child of the table, and the difference is only visible if you style it.
Conventionally it goes first, because the name of a table belongs with its introduction, before the reader starts scanning the rows.
<table>
<caption>Support response times by priority</caption>
...
</table>There is one detail that catches people. A caption is not a heading. It does not appear in the document outline, and it is not a way to title a section.
If a table needs a visible heading in the page flow, then you put an <h3> above it, and you keep the caption for the table's own name.
And a table that scrolls sideways should say so. A short note below the table, such as "scroll sideways to see all columns", saves a reader who cannot see the scrollbar from assuming that the data is cut off. The same note in the aria-label of the scroll region helps screen reader users to understand why their cursor is moving sideways.
Quick reference
- A table is for tabular data, with a caption, a header row, and header cells that say what they label.
- The
scope="col"and thescope="row"are what make the associations explicit. - You use the
colspan, therowspan, and theheadersfor complex shapes. - You style the table and not the individual cells as separate boxes.
- Layout tables should be the CSS grid instead.
- A scrollable table wrapper needs the
tabindex="0"to be keyboard reachable.
Try it yourself: you build a table with a caption, three column headers, and row headers. Then you read it with a screen reader, or with the accessibility tree in the developer tools. You remove the scope attributes and you check what happens to the announced text, because that difference is the whole point of the markup.