HTML · The document layer
How do you build an accessible HTML table?
Short answer
Tables are for tabular data, not layout. Use caption, thead, tbody, th with scope, and keep one header row so assistive technology can associate cells with headers.
A table is a relationship between rows, columns and headers. When the markup preserves that relationship, a screen reader can announce the correct header as a user moves between cells.
<table>
<caption>Quarterly revenue by region</caption>
<thead>
<tr>
<th scope="col">Region</th>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">North</th>
<td>120</td>
<td>150</td>
</tr>
</tbody>
</table>What makes a table accessible
- Use a caption to name the table and explain what it contains
- Use th for headers and td for data cells
- Set scope=col or scope=row so headers map to the right cells
- Keep the header structure consistent; avoid merged cells that break the mapping
- Never use tables for page layout
Complex tables with multiple header levels are possible, but they quickly become hard to navigate. If the data is very complex, consider splitting it into smaller tables or providing a summary.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does the scope attribute do?
- 2Why is a caption useful?
- 3When would you use colspan or rowspan?
- 4Why should tables not be used for layout?
Say it in the interview
I use tables only for data, because the markup encodes relationships between rows, columns and headers. I add a caption, use thead and tbody, mark header cells with th, and set scope to col or row. That lets a screen reader announce the right header when someone moves between cells. For layout I use CSS, not a table, and I keep complex merged headers to a minimum.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live HTML mock interview and get scored feedback on depth, clarity and confidence.