HTML Table Headers: Captions and Scope
Use meaningful header cells
Use th when a cell labels other cells. A header is a semantic relationship, not just bold styling. caption identifies the table and belongs before the rows.
<table> <caption>Daily orders</caption> <tr> <th>Day</th> <th>Orders</th> </tr> <tr> <td>Monday</td> <td>12</td> </tr></table>The table has a caption and two headers.
Mark column headers
A scope="col" header applies to the column it labels. Simple tables often have inferable header associations, but explicit scope helps make the author’s intent clear.
<table> <caption>Stock</caption> <tr> <th scope="col">Item</th> <th scope="col">Count</th> </tr> <tr> <td>Pen</td> <td>4</td> </tr> <tr> <td>Notebook</td> <td>7</td> </tr></table>Count describes both numbers in the second column.
Mark row headers as well
When a value is identified by a row label and a column label, use scope="row" on the row header. For example, 18 means North revenue, not an isolated number. Assistive technology can use these relationships when navigating the table.
<table> <caption>Revenue by branch (EUR)</caption> <tr> <th scope="col">Branch</th> <th scope="col">Revenue</th> </tr> <tr> <th scope="row">North</th> <td>18</td> </tr> <tr> <th scope="row">South</th> <td>24</td> </tr></table>Both branch names are row headers.
Common mistakes and practice
Do not replace th with a bold td. Do not use a caption as a column header or put scope on td. Try giving a two-column table a clear caption and both kinds of headers.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Table Headers: Captions and Scope — Knowledge Check
Apply table structure and accessibility concepts from this lesson.
Which element identifies the overall subject of a table?
Which markup identifies a header for its row?
Why is bold text inside td not equivalent to th?
Which markup identifies a column header?
Where should a table's overall caption be placed?