# TD Headers Attr

> All cells in a table element that use the headers attribute must only refer to other cells in the same table.

Source: https://knowledge.evinced.com/web/web-validations/td-headers-attr

All cells in a table element that use the `headers` attribute must only refer to other cells in the same table.

A data table has to convey clear relationships between header cells and the data they label. When a `<td>` uses the `headers` attribute, the value must reference the `id` of a header cell (`<th>`) that lives in the very same table. Otherwise, screen-reader users hear the wrong header, or none at all, and cannot work out how the data is organised. Using the attribute correctly (or, whenever possible, adding a `scope` attribute to each `<th>`) keeps table navigation predictable for everyone.

## Pass Patterns

### Data cells reference header cells within the same table

Each `headers` value matches an `id` that appears in a `<th>` inside the same table row or column, so assistive technology can announce the right pairing.

```html
<table>
    <tr>
        <th id="name" scope="col">Name</th>
        <th id="score" scope="col">Score</th>
    </tr>
    <tr>
        <td headers="name">Alex</td>
        <td headers="score">95</td>
    </tr>
</table>
```

## Fail Patterns

### Data cell points to a header that is not in the same table

The first `<td>` points to `external-header`, an `id` that sits in a different table. A screen reader will not find the target header and will announce the cell with no context or fall back to the text of the `<th>` in the scope.

```html
<!-- First (hidden) table that defines a header used elsewhere -->
<table hidden>
    <tr><th id="external-header">Sold out</th></tr>
</table>


<!-- Visible table with broken reference -->
<table>
    <tr>
        <th id="product" scope="col">Product</th>
        <th id="price" scope="col">Price</th>
    </tr>
    <tr>
        <td headers="external-header">Widget A</td> <!-- ❌ Wrong table -->
        <td headers="price">10.00</td>
    </tr>
</table>
```

## WCAG techniques

### Sufficient techniques

-   [H43: Using id and headers attributes to associate data cells with header cells in data tables](https://www.w3.org/WAI/WCAG22/Techniques/html/H43)

### Failure techniques

-   [F90: Failure of Success Criterion 1.3.1 for incorrectly associating table headers and content via the headers and id attributes](https://www.w3.org/WAI/WCAG22/Techniques/failures/F90)

## Try It Yourself

### Using a screen reader

**New to screen reader testing, or need a refresher?**  
Review this article first: [Practical guides for using screen readers](https://knowledge.evinced.com/a11y-essentials/practical-guides-for-using-screen-readers)

1.  Load the page and open a screen reader, then move focus into the data table.
2.  Navigate cell by cell with the table-navigation commands of your screen reader.
3.  Listen for the announced header before each data value.

**Expected result:** The header that is announced matches the visible column or row header.

**Actual result:** The header is missing or mismatched, so the data makes little sense, or it falls back to the table header of the column or row if it exists.

## FAQ

**How does this issue relate to 1.3.1 Info and Relationships?**

SC 1.3.1 requires that information conveyed visually is also available programmatically. Correct references in the `headers` attribute expose header-data relationships in the accessibility tree, allowing assistive technology to communicate the same structure that sighted users perceive.

**Why is this issue marked as Serious?**

When headers are mis-mapped, screen-reader users must guess which data belongs to which header, or receive misleading information, slowing them down and increasing errors.

## Standards and Regulations

| Standard | Success Criterion | Reference |
| --- | --- | --- |
| WCAG 2.2 | [1.3.1 Info and Relationships](https://www.w3.org/TR/WCAG22/#info-and-relationships) (A) | Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text. |
| EN 301 549 | [9.1.3.1 Info and Relationships](https://www.etsi.org/standards/etsi-301-549) | Same as the WCAG text. |
| Section 508 | [1194.22(g)](https://www.federalregister.gov/documents/2018/01/18/2018-00712/section-508-standards-update#d22) | Row and column headers shall be identified for data tables. |
| Section 508 | [1194.22(h)](https://www.federalregister.gov/documents/2018/01/18/2018-00712/section-508-standards-update#d22) | Markup shall be used to associate data cells and header cells for data tables that have two or more logical levels of row or column headers. |
| 508 Trusted Tester | [1.3.1-cell-header-association, 14.B](https://section508coordinators.github.io/TrustedTester/tables.html#check-131-cell-header-association) | All data cells are programmatically associated with relevant headers. |

## Personas impacted by this issue

-   [Screen Reader](https://knowledge.evinced.com/a11y-essentials/personas#screen-reader)
-   [Braille](https://knowledge.evinced.com/a11y-essentials/personas#braille)

## Learn More

-   [W3C’s Tables Tutorial](https://www.w3.org/WAI/tutorials/tables/)

## Related Issues

-   [table-duplicate-name](https://knowledge.evinced.com/web/web-validations/table-duplicate-name)
-   [empty-table-header](https://knowledge.evinced.com/web/web-validations/empty-table-header)
-   [th-has-data-cells](https://knowledge.evinced.com/web/web-validations/th-has-data-cells)
-   [scope-attr-valid](https://knowledge.evinced.com/web/web-validations/scope-attr-valid)
