caption
The HTML <caption> element gives a table a title or short explanation. It helps readers understand what the table represents before they explore its cells.
What you will learn
- How
captioncommunicates a table’s purpose - Where to place it and how to write the basic markup
- Why a table description helps all users, including screen-reader users
Basic syntax
<table>
<caption>Weekly study hours</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">Hours</th></tr>
</thead>
<tbody>
<tr><th scope="row">Monday</th><td>2</td></tr>
</tbody>
</table>
Place caption directly inside table, usually before thead, tbody, or tr. A table can have only one caption.
Write a useful caption
A good caption answers “What is this table about?” in a short phrase. Include the subject, time range, or comparison when that context is important.
- Good
Monthly sales by product, April 2026- Too vague
Datadoes not tell the reader what the numbers mean.
Caption is not a cell
caption describes the table; it is not a row or column heading. Use th for headers and scope or appropriate header associations for complex tables.
CSS can change where the caption appears visually, but its semantic relationship with the table remains. Do not replace it with a disconnected heading when the text is specifically the table’s title.
Common mistakes
- Putting
captionoutside thetableelement. - Using several captions for one table instead of one clear description.
- Using
tdas a fake title row. - Relying on a visual title while leaving the table’s purpose unclear in the markup.