How do I mark up a data table with clear row and column headers?
Quick answer
For a genuine data table, mark header cells with <th> and ordinary data cells with <td>. In a straightforward table, use scope="col" for headers that label columns and scope="row" for headers that label rows. More complex header relationships may need id and headers instead. Use a table for related tabular data, not just to position page content. [S1]
The question, the details, the next step.
A practical checklist
Confirm the content is related tabular data, not a table used only for page layout.
Mark header cells with
<th>and ordinary data cells with<td>.Use
scope="col"for straightforward column headers andscope="row"for straightforward row headers.Check that each row and column label clearly describes the values it relates to.
For grouped or otherwise complex headers, map the relationships and consider
idandheaders.
A few more useful answers
Can I make a data cell look like a header without using `<th>`?
Visual styling alone does not mark a cell as a header. For a data table, use <th> for header cells and <td> for data cells. [S1]
Do all tables need both row and column headers?
No. Use headers that match the actual relationships in the table. A straightforward table may have column headers, row headers, or both; the example uses both to make its labels clear.
What does this guidance establish about complex tables?
It establishes that complex header relationships may require id and headers, but it does not give a complete design for every multi-level table. [S1]
Sources
References used for this guide.
- [S1] W3C WAI Tables Tutorial: Marking up data-table headers w3.org · Checked
