Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 122 ยท Tables

Accessible Tables

Make data tables work for screen-reader users. Connect cells to headers with scope and the headers attribute, describe tables well, and avoid nested and layout tables.

A sighted reader understands a table at a glance: the eye jumps to the column header, then to the row label, then back to the number. A screen-reader user can't glance. They move through the table one cell at a time, and the screen reader has to announce the right headers with each cell so the numbers make sense.

When the HTML describes the table correctly, this works beautifully. When it doesn't, the user hears a stream of disconnected values: "14โ€ฆ 9โ€ฆ 22โ€ฆ". This lesson brings together everything from the chapter and adds the tools for complex tables.

How screen readers read tables

When a screen-reader user enters a table, they typically hear its caption and size, for example "Monthly rainfall, table with 5 rows and 4 columns". Then they use table-navigation keys (such as Ctrl+Alt+arrow keys in NVDA and JAWS on Windows, or Control+Option+arrow keys in VoiceOver on macOS) to move up, down, left and right.

As they move, the screen reader announces the headers that changed along with the cell's content. Moving right along a row, they hear the new column header; moving down a column, the new row header. That only works if the screen reader knows which header cells belong to which data cells.

There are three levels of support for that, from simplest to most explicit:

  1. <th> cells in the first row and column. Browsers can usually work out the relationships on their own.
  2. scope on every <th>. You state the direction explicitly.
  3. The headers attribute. You list, for each data cell, exactly which header cells apply.

Use the simplest one that fully describes your table.

Simple tables: <th> plus scope

Most tables have one row of column headers and, optionally, one column of row headers. For these, scope="col" and scope="row" are all you need, as you saw in Table Headers, Sections and Captions.

A simple accessible table

When a user reaches 39, the screen reader can announce "Lisbon, May, 39". Notice the empty top-left cell is a <td>, not a <th>: it labels nothing, so it shouldn't pretend to be a header.

Grouped headers: scope="colgroup" and scope="rowgroup"

When headers group several columns or rows, add the group scopes:

  • A header spanning a set of columns gets scope="colgroup", and the columns should be grouped with <colgroup> (see Column Groups).
  • A header labeling all the rows of a <tbody> gets scope="rowgroup".
HTML
<colgroup></colgroup>
<colgroup span="2"></colgroup>
<colgroup span="2"></colgroup>
<thead>
  <tr>
    <td rowspan="2"></td>
    <th colspan="2" scope="colgroup">Saturday</th>
    <th colspan="2" scope="colgroup">Sunday</th>
  </tr>
  <tr>
    <th scope="col">High</th>
    <th scope="col">Low</th>
    <th scope="col">High</th>
    <th scope="col">Low</th>
  </tr>
</thead>

Now a cell under "Sunday / Low" can be announced with both of its headers.

Complex tables: id and headers

Some tables are irregular: headers in the middle of the data, several levels of spanning, or header cells that apply to scattered cells. Here scope runs out of power, and you connect cells to headers by hand:

  1. Give every header cell a unique id (see IDs).
  2. On each data cell, list the ids of all its headers in the headers attribute, separated by spaces.
Linking cells with headers and id

With these links, the cell $102.00 is announced with "Visit, Packed lunch, Group of 24": three headers, from three different places in the table. (This particular table could also be marked up with one <tbody> per section and scope="rowgroup". Reach for headers when no arrangement of scopes describes the table.)

headers is powerful but fragile. Every id must exist and be unique, and each new row means new links. Before writing it, ask whether the table could be split into two simpler tables instead. Simpler tables are better for everyone, not only screen-reader users.

Describe the table

A table needs a name, and sometimes a short explanation.

  • Always use a <caption>. It names the table, is announced on entry and helps everyone find the right table on a busy page.
  • Explain complex tables. If readers need to know how to read the table ("Prices include tax. A dash means the route doesn't run that day."), put it in a paragraph next to the table and link the two with aria-describedby:
HTML
<table aria-describedby="ferry-note">
  <caption>Island ferry departures</caption>
  โ€ฆ
</table>
<p id="ferry-note">Times are local. A dash means no sailing that day.</p>

You can also put the explanation inside the caption itself, for example in a <details> element so it is available but out of the way.

The summary attribute is obsolete. Old tutorials put a description in <table summary="โ€ฆ">. It is no longer part of HTML; use a caption or a linked paragraph instead.

Pitfalls to avoid

Layout tables

Using a table to arrange a page makes screen readers announce rows and columns that mean nothing, as you saw in Tables. If you inherit old layout tables you can't remove right away (email templates are a common case), add role="presentation" to the <table>. That tells assistive technology to ignore the table structure and read the content as plain text. Never use <th>, <caption> or scope in a layout table.

Nested tables

A table inside a table cell is confusing to navigate: the user enters a second grid and must work out where they are. It's almost always clearer to flatten the data, split it, or use colspan and rowspan for the grouping.

Losing table semantics with CSS

Some browsers stop exposing an element as a table to assistive technology when its display is changed, for example to block or flex to build a "responsive card" layout. Prefer a scrolling wrapper (see Styling Tables with CSS). If you must restyle, test with a real screen reader.

Other common problems

  • Empty or meaningless headers, such as an unlabeled column of icons. Give every column a header, even if you hide it visually with CSS.
  • Information conveyed only by color, like red numbers for losses. Add a minus sign, a word or an icon with text.
  • Tables as images. A screenshot of a spreadsheet can't be navigated at all. Use a real table.
  • Huge single tables. Break very long data into sections with <tbody> groups, or into several tables with their own captions.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the simplest markup that lets a screen reader announce "Lisbon, May" for a cell in a regular grid?

    For a simple grid with one row of column headers and one column of row headers, <th> with scope fully describes the relationships.
  2. 2. What goes in a data cell's headers attribute?

    headers lists ids. Each id must belong to a header cell in the same table.
  3. 3. You can't remove an old layout table yet. What should you add to it?

    role="presentation" tells assistive technology to ignore the table structure, so the content is read as normal text.
  4. 4. Where should a longer explanation of how to read a table go?

    summary is obsolete, and title tooltips are unreliable. A visible paragraph linked with aria-describedby, or caption text, helps everyone.

Summary

  • Screen-reader users explore tables cell by cell and rely on the correct headers being announced.
  • For simple tables, use <th> with scope="col" and scope="row"; use colgroup and rowgroup for grouped headers.
  • For irregular tables, give headers ids and list them in each cell's headers attribute, or split the table.
  • Always name tables with <caption>; link longer explanations with aria-describedby.
  • Avoid layout tables (or mark legacy ones role="presentation"), nested tables, and display changes that strip table semantics.

That completes the Tables chapter. Next, the Images and Media chapter begins: Images.