The HTML <th> tag
The HTML <th> element defines a header cell in a table. Give it a scope (col or row) so assistive technology announces it with the right data cells. It is bold and centered by default.
Overview
The <th> (table header) element labels a row or a column of data. Browsers render it bold and centered, but the important part is invisible: screen readers announce it as the header for the cells it governs, so a user navigating the table hears "Price, $9" rather than just "$9".
Make that association explicit with the scope attribute: scope="col" for a column header, scope="row" for a row header. This is the single most valuable thing you can do for table accessibility, and it takes one attribute. The abbr attribute can give a long heading a short spoken form.
For complex tables with multiple levels of headers, the scope attribute is not enough. Connect each data cell to its headers with the headers attribute referencing the headers' ids. As with <td>, style header cells with CSS rather than the obsolete presentational attributes.
Syntax
<th scope="col">Product</th>
Attributes
The <th> element supports the following attributes, in addition to the global attributes available to every HTML element.
| Attribute | Value | Description |
|---|---|---|
abbr |
A short string. | Gives a table header cell a short abbreviated label. |
colspan |
A positive integer (default 1). | Spans a table cell across columns. |
headers |
A space-separated list of header cell ids. | Links data cells to header cells for accessibility. |
rowspan |
A non-negative integer (0 means span to the end of the section). | Spans a table cell across rows. |
scope |
row col rowgroup colgroup |
States what a table header cell labels. |
Example
<style>table{border-collapse:collapse}th,td{border:1px solid #cbd5e1;padding:6px 10px}</style>
<table>
<tr><th scope="col">Name</th><th scope="col">Role</th></tr>
<tr><th scope="row">Ada</th><td>Engineer</td></tr>
</table>
Best practices
- Set
scope="col"orscope="row"on every header cell so screen readers associate it correctly. - Use
<th>for all header cells, never a styled <td>. - Give long headings a short spoken form with the
abbrattribute. - For multi-level headers, link data cells to headers with the
headersattribute and matchingids.
Accessibility
Frequently asked questions
What is the th element?
What is the difference between th and td?
<th> is a header that labels data; <td> holds the data itself.What does the scope attribute do?
scope="col") or a row (scope="row"), making the association explicit for assistive technology.How do I make a data table accessible?
<th> for headers with scope, add a <caption>, and for complex tables connect cells to headers with the headers attribute.