How do I connect a table's row and column headers to data cells?
Quick answer
For a complex HTML table, give every header cell a unique id, then list the IDs of all headers that apply to each data cell in that cell’s headers attribute. This helps when relationships are unclear from the layout, such as with grouped or changing headings. For headers spanning row or column groups, scope="rowgroup" or scope="colgroup" may fit; choose the pattern that matches the table’s structure. [S1] [S2]
The question, the details, the next step.
A practical checklist
Give every header cell a unique
id.List every applicable header ID in each complex data cell’s
headersattribute.Use row-group or column-group scope only when it matches the table’s structure.
Recheck cell associations after changing rows, columns, or grouped headings.
Consider splitting a table if its relationships remain too complex.
A few more useful answers
Does a table caption connect headers to data cells?
No. A caption can identify the table, but it does not replace associations between headers and data cells. [S1]
Can one data cell have several associated headers?
Yes. List the relevant header IDs, separated by spaces, in that cell’s headers attribute. [S1]
Should I use `scope="colgroup"` for every multi-level heading?
No. Use group scope when it matches the actual row or column grouping; for relationships too complex for that pattern, use explicit header IDs and cell associations. [S2]
Sources
References used for this guide.
- [S1] W3C WAI Tables Tutorial: Multi-Level Headers w3.org · Checked
- [S2] W3C WAI Tables Tutorial: Irregular Headers w3.org · Checked
