Skip to content

TBL-001 Build data in rows and columns as a table in code, with its headings marked as headers

Level
Rule
Verdict
Requirement
Area
Tables
Status
proposed, version 1.0.0

Rule

When values are shown in rows and columns under headings, build them as a table in code. Mark each heading cell as the header of its column or row, so assistive technology can tell which headings every value belongs to.

Examples

Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.

Do: A real table with headers

Water samples
SitepHNitrate (mg/l)Collected by
Mill Lane footbridge7.412R. Okafor
Harbour steps7.19M. Lindqvist
Quarry pond6.8Not measuredR. Okafor
Weir Road culvert7.615T. Haddad
or click a cell
Click a value, or press Next cell, and read what the code ties to it. 7.4 sits under pH, in the row for Mill Lane footbridge. The empty nitrate reading is a cell that says “Not measured”. Tab to the table area to scroll it from the keyboard.

Don't: A grid of divs that looks like a table

Water samples

Site
pH
Nitrate (mg/l)
Collected by
Mill Lane footbridge
7.4
12
R. Okafor
Harbour steps
7.1
9
M. Lindqvist
Quarry pond
6.8
Not measured
R. Okafor
Weir Road culvert
7.6
15
T. Haddad
or click a cell
The same picture, built from div elements. Click 7.4, or press Next cell: it is a loose value, with no column or row heading in the code. A sighted person sees the ties and a screen reader user does not.

Do: A checkbox column that has a heading

Water samples
SelectSitepHCollected by
Mill Lane footbridge7.4R. Okafor
Harbour steps7.1M. Lindqvist
Quarry pond6.8R. Okafor
Weir Road culvert7.6T. Haddad
or click a cell
The column of checkboxes has the heading Select, drawn for screen readers only. The note under the table starts on the first checkbox: its column heading is found, and so is its row. Press Next cell to move on, and tick a few boxes.

Don't: An empty heading over the checkboxes

The same table, but the heading cell over the checkboxes is empty. The table is shown as a picture, since a live one would fail the page's own checks. The note under it starts on the first checkbox: the code finds a heading cell with nothing in it, so the column has no name. Next cell moves the note on.

Why

A sighted person reads a value by glancing up at its column and across to the start of its row. "7.4" means nothing alone; under pH, in the row for Mill Lane footbridge, it is a reading. A screen reader user gets that meaning only if the code holds the same ties. In a real table, moving from cell to cell, the screen reader says the heading of the new column or row, and the person can move down one column or along one row. A grid of div elements styled to look like a table gives them a run of loose numbers instead.

WCAG 2.2, 1.3.1 Info and Relationships requires that relationships shown by the layout can also be read from the code. The Working Group lists a data table whose headings are not marked as headers as a failure (F91). That failure accepts several ways to pass: header elements, scope on the header cells, headers and id on the data cells, or the ARIA roles for tables and their headers. So the criterion asks that the headers can be found in code. It does not ask for the table element, for th or for scope as such; those are the techniques in H51 and H63. 4.1.2 Name, Role, Value supports the rule: the roles a table exposes are what lets software treat it as one.

Do

  • A council's page Water samples lists one row per site, with the columns Site, pH, Nitrate (mg/l) and Collected by. It is built with shadcn's Table: the headings are TableHead cells inside TableHeader, and the values are TableCell cells in TableBody. TableHead renders a th and TableCell a td, so the ties are in place.
  • Our own advice, beyond the requirement: give each column heading scope="col" and render the cell that names the row as a row header, <TableHead scope="row">Mill Lane footbridge</TableHead>, styled like the other body cells with font-normal. A screen reader then says the site's name as the person moves along its row. The criterion needs a row header only where the first column is what gives the other cells their meaning, which in a data table it usually is.
  • With TanStack Table, map each header group to a TableRow of TableHead cells. Give each one colSpan={header.colSpan}, and render flexRender(header.column.columnDef.header, header.getContext()) inside it, or nothing when header.isPlaceholder is true. Map the rows of table.getRowModel() to TableRow with TableCell, or with TableHead scope="row" for the column that names the row.
  • Give every header cell text, also over a column of checkboxes or row actions. When the column needs no visible heading, put "Select" or "Actions" in an sr-only span, so the column still has a name.
  • Keep the header row and the body in one table. To keep the headings in view while the body scrolls, let the table scroll in its own area of limited height and make TableHeader sticky with sticky top-0 bg-background. shadcn's Table wraps the table in a div with overflow-x-auto, so a sticky header there sticks to that div, not to the page. Give that wrapper a limit such as max-h-96 and overflow-auto in your copy of table.tsx; the className you pass to Table goes to the table, not to the wrapper.
  • When a group heading spans several columns, such as Nitrate (mg/l) over Upstream and Downstream, plain th is not enough. Use scope="colgroup" on the group heading or tie each cell to its headings with headers and id.
  • Leave an empty value as a cell, so the columns stay in line in code. Our own advice: write "Not measured" or a dash, which is read as text, rather than leaving the cell blank.
  • If the table is too wide for a narrow screen, give it its own scroll area as LAY-001 says, and keep the table structure inside it. shadcn's Table already renders a scrolling wrapper, but with no tabIndex, role or name, so add the focus and the name LAY-001 asks for in your copy of table.tsx.
  • If a narrow layout turns each row into a card, put the heading text next to each value in the card's markup, such as "pH: 7.4", so each value still carries its label. Our own advice: do not rely on text added with CSS content for this, since screen readers do not all read it.
  • A table built from div elements with role="table", role="row", role="columnheader", role="rowheader" and role="cell" meets the criterion too. Our own advice is to use the native elements, which shadcn's Table already renders: one wrapper without its role breaks the whole ARIA structure, and the native one cannot break that way.
  • In a long table that renders only the rows in view, our own advice is to set aria-rowcount on the table and aria-rowindex on each row, so a screen reader can say where in the full list the person is.

Don't

  • Build the Water samples grid from div className="grid grid-cols-4", with the heading row as one more div in font-medium text-muted-foreground.
  • Render the TanStack header group as a TableRow of TableCell, so every heading is a td.
  • Put the headings in one Table above a second, scrolling Table for the body, so no value is tied to its heading.
  • Leave the header cell over the row checkboxes empty.
  • Set display: block or display: flex on table, tr or td to make the table fit a phone. Some browsers then drop the table semantics.
  • Use a table to lay out a form or a page. A table for layout has no th and no caption.
  • Turn rows into cards on a phone and drop the headings, leaving "7.4", "12" and "R. Okafor" with nothing to say what they are.

Exceptions

  • Content that is not a grid of values. A set of cards in which every value carries its own visible label, such as "Collected by R. Okafor", already holds the tie in its text and is outside this rule. Choosing a table or cards is not part of it.
  • One record. Labels beside the values of a single record can be a description list (dl) or a two-column table with row headers. Both meet the criterion.
  • Interactive grids. A grid that people edit in place and move through with the arrow keys has its own roles and keyboard model, and this rule does not cover it.
  • Neighbouring rules. Sorting by a column is TBL-002, actions in a row are TBL-003 and the table's title is TBL-004. Reflow is LAY-001, the order of the columns in code is LAY-002, and the names of controls inside cells, such as a checkbox on each row, are FRM-010.

Verdict

Requirement. Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work

Stances on TBL-001
SourceRoleStancePage
WCAG 2.2LawRequires1.3.1 Info and Relationships
WCAG 2.2LawSupports4.1.2 Name, Role, Value
Material DesignJudge No position
Apple Human Interface GuidelinesJudge SupportsLists and tables
Carbon Design SystemJudge SupportsData table: usage
Data table: accessibility
GOV.UK Design SystemExpert witness SupportsTable
Nielsen Norman GroupExpert witness SupportsData Tables: Four Major User Tasks, by Page Laubheimer
Mobile Tables: Comparisons and Other Data Tables, by Amy Schade

Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.

History

  • Version 1.0.0, : First version.

Last checked against the other rules for conflicts on .

More in Tables: 3 rules and 1 guideline · All rules