The HTML headers attribute
The HTML headers attribute associates a data cell with its header cells by their ids, for accessibility in complex tables. It is used on the <td> and <th> elements.
Overview
The headers attribute links data cells to header cells for accessibility. It is used on the <td> and <th> elements.
It defines table structure: spanning cells across rows or columns, and connecting data cells to their headers. These attributes are central to making data tables understandable to screen-reader users.
Syntax
<th id="q1">Q1</th> … <td headers="q1">100</td>
Values
| Value |
|---|
| A space-separated list of header cell ids. |
Best practices
- Once a cell has a
headersattribute, the table model builds its header list from those ids alone, ignoringscopeand the cell's position. List each header that applies, row and column headers alike. - Point each id at a <th> in the same table, as the standard requires. An id that names a
<td>breaks that rule, and an id for an element outside the table adds no header at all. - Header references must not loop. A
<th>must not list its own id, and no chain of headers references may lead back to the cell it started from. - A
<th>whose own headers list points at a broader heading doesn't pass that link on to data cells. Add the broader heading to each data cell's list as well. - The
headersDOM property returns the attribute as one string, spacing included, not as a token list. Split it on whitespace to read the ids, and assign a whole new string to change them.
Accessibility
In complex tables where scope is not enough, headers explicitly ties each data cell to its header cells so screen readers announce the right context.























