Skip to content

Articles · Good practices

Data tables: caption, th and scope, and what screen readers do with them

With caption, th and scope, screen readers announce each cell’s row and column headers. Without them, the person hears figures with no context. RGAA 5.3, 5.4, 5.6, 5.7 and 5.8.

By

· Published on

A price table: three plans in columns, four services in rows. On screen, the eye crosses the row and the column. With a screen reader, the person moves from cell to cell. If the table is well coded, the screen reader announces “100 GB” together with the headers that apply to it, “Storage” and “Pro plan”. Otherwise, they hear “100 GB” and have to guess the rest. The order and detail of the announcement vary with the screen reader and its settings.

A title linked to the table

The table’s title says what it contains before the person enters it. The <caption> element, first child of the <table>, links it to the table. The RGAA checks this in criterion 5.4: « Pour chaque tableau de données ayant un titre, le titre est-il correctement associé au tableau de données ? » (For each data table that has a title, is the title correctly associated with the data table?) Its glossary also allows the title, aria-label and aria-labelledby attributes, but recommends <caption>, the only one supported by all assistive technologies.

Declared headers

To the browser, a bold cell on a grey background is still an ordinary cell. Criterion 5.6 asks for headers to be declared: « Pour chaque tableau de données, chaque en-tête de colonne et chaque en-tête de ligne sont-ils correctement déclarés ? » (For each data table, are each column header and each row header correctly declared?) The RGAA accepts the <th> element or a columnheader or rowheader WAI-ARIA role. Its glossary recommends <th>, which assistive technologies render best.

Criterion 5.7 then checks that each cell is linked to its headers: « Pour chaque tableau de données, la technique appropriée permettant d’associer chaque cellule avec ses en-têtes est-elle utilisée (hors cas particuliers) ? » (For each data table, is the appropriate technique used to associate each cell with its headers, except in particular cases?) For a simple table, the scope attribute is enough: scope="col" for a column header, scope="row" for a row header. The particular case: when the headers sit on a single row or a single column, <th> elements without scope are accepted. In the example below, the headers take up the first row and the first column, hence the scope attributes. For a complex table, with headers on several levels, you link each cell to its headers with the id and headers attributes.

<table>
  <caption>Monthly prices by plan</caption>
  <tr><td></td><th scope="col">Essential plan</th><th scope="col">Pro plan</th></tr>
  <tr><th scope="row">Storage</th><td>20 GB</td><td>100 GB</td></tr>
</table>

Data table or layout table?

A table that only serves to place blocks side by side is a layout table. Criterion 5.3 checks that its content remains understandable once linearised: « Pour chaque tableau de mise en forme, le contenu linéarisé reste-t-il compréhensible ? » (For each layout table, does the linearised content remain understandable?) Its test 5.3.1 also requires the <table> element to have a role="presentation" attribute. Criterion 5.8 adds: « Chaque tableau de mise en forme ne doit pas utiliser d’éléments propres aux tableaux de données. Cette règle est-elle respectée ? » (Each layout table must not use elements specific to data tables. Is this rule respected?) Its test rules out <caption>, <th>, <thead>, <tfoot> and the summary attribute, as well as the scope, headers and axis attributes on cells. Today, layout is done in CSS: layout tables are mostly a legacy, common in emails.

Our advice

  • Give every data table a <caption>, even a short one.
  • Prefer several simple tables to one complex table.
  • Test by moving cell by cell with NVDA (Ctrl+Alt+arrow keys): each cell must be understandable with the headers announced.

Sources

  • RGAA 4.1.2, criteria 5.3, 5.4, 5.6, 5.7 and 5.8, and glossary (entries « Tableau de données ayant un titre » and « En-tête de colonne ou de ligne »). accessibilite.numerique.gouv.fr (in French)
  • W3C, WAI, Tables Tutorial. w3.org

Leave a Reply

Every comment is reviewed before it is published. Your email address will not be published. Fields marked with an asterisk (*) are required. See the privacy policy.

Read also