Back to HTML

Accessible Tables with th, scope and caption

Coding Tutorials Team 20 June 2026

Tables are for data with two dimensions, where each cell sits at the intersection of a row and a column. Marked up properly they are highly navigable. Marked up as a grid of plain cells they are close to unusable for anyone who cannot see the whole thing at once.

Why header cells matter

A sighted reader glances up a column to see what a value means. A screen reader user cannot, and instead relies on the software announcing the relevant headers as they move between cells.

That only works if the headers are marked as headers. A table built entirely from ordinary cells announces bare values with no context, so the user hears a string of numbers with no indication of what any of them measure.

The basic structure

<table> <caption>Page load times before and after optimisation</caption> <thead> <tr> <th scope="col">Page</th> <th scope="col">Before</th> <th scope="col">After</th> </tr> </thead> <tbody> <tr> <th scope="row">Home</th> <td>4.2s</td> <td>1.1s</td> </tr> </tbody> </table>

Note that the first cell of each body row is a header cell too, because it labels the row. This is frequently missed, and it is what allows a screen reader to announce both the row and the column when reading a value.

The scope attribute

Scope tells the browser which cells a header applies to. A value of col means it heads the column beneath it, and row means it heads the cells across from it.

Without scope, software has to guess from position, and it guesses correctly for simple tables and unreliably for anything more complex. Adding the attribute costs almost nothing and removes the ambiguity entirely.

For headers spanning multiple columns or rows, the values colgroup and rowgroup exist, used alongside the colspan and rowspan attributes.

The caption element

The caption is the table's title and must be the first child of the table element. It is announced when a screen reader encounters the table, which lets a user decide whether to explore it or move on.

This is more useful than a heading above the table, because the association is explicit rather than inferred from proximity. Where a design has no room for a visible caption, hide it with the visually hidden technique rather than omitting it.

Grouping rows

The thead, tbody and tfoot elements group the header rows, the data rows and any summary rows. They carry structural meaning and have a practical benefit as well: when a long table is printed, browsers repeat the head on each page.

The browser inserts a tbody automatically even when you do not write one, which is why a CSS rule targeting a row as a direct child of a table never matches. Inspecting the accessibility tree makes this obvious and it surprises people every time.

Complex tables

Tables with multiple levels of headers, or headers that do not sit in the first row or column, need more than scope. The headers attribute on each data cell lists the ids of the header cells that apply to it, which establishes the relationships explicitly.

This is laborious and worth avoiding where possible. A complex table can usually be split into several simpler ones, which is easier to mark up and considerably easier for everyone to read.

Never use tables for layout

This was standard practice before CSS layout existed and has no justification now. A layout table announces itself as a table, states its dimensions, and invites the user to navigate it as data, all of which is misleading.

It also produces markup where the reading order is determined by the grid rather than by the content, so a screen reader may read a page in an order that makes no sense. Flexbox and Grid do the job properly and are simpler to write.

The one surviving exception is HTML email, where support for modern layout remains poor enough that table layout is still common practice.

Tables on narrow screens

A wide table does not fit a phone, and the common responses each have costs. Allowing horizontal scrolling preserves the structure and requires a focusable scroll container so keyboard users can reach it. Restructuring each row into a stacked card is readable and loses the ability to compare down a column.

Whichever you choose, the underlying markup should remain a properly structured table, with the presentation handled in CSS. Changing the display property of table elements can detach the semantics in some browsers, so adding explicit roles back is sometimes necessary when restyling heavily.