- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <th> Tag
HTML Tags
HTML <th> Tag
The th tag makes a header cell: the label of a column or a row. It is bold and centered by default, but the real reason to use it is that screen readers read it out with every data cell, so a blind user hears "Savings, $100" instead of just "$100".
Syntax
html
<th scope="col|row">Header Content</th>| Attribute | What it does |
|---|---|
| scope | Says what the header labels: col for its column, row for its row, or colgroup / rowgroup for a group. |
| colspan | How many columns the cell spans. |
| rowspan | How many rows the cell spans. |
| abbr | A short version of the header text, for screen readers to repeat with each cell. |
| headers | The ids of other header cells that label this one, for complex tables with several header levels. |
scope is the one to remember. For a simple table it is often guessed correctly without it, but adding it makes the meaning certain.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML th Tag Example</title>
</head>
<body>
<h2>Example of the <th> Tag</h2>
<table border="1">
<tr>
<th scope="col">Month</th>
<th scope="col">Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$150</td>
</tr>
</table>
</body>
</html>"Month" and "Savings" appear bold and centered at the top, labelling the two columns below them.
Row headers too
Headers do not have to be at the top. In a table where each row describes one thing, the first cell of each row can be a header:
Column and row headers together
html
<table>
<tr>
<td></td>
<th scope="col">Price</th>
<th scope="col">Storage</th>
</tr>
<tr>
<th scope="row">Basic</th>
<td>₹99</td>
<td>10 GB</td>
</tr>
</table>A screen reader on "₹99" now says "Basic, Price, ₹99".
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
- Do not fake headers with
<td><b>Name</b></td>. It looks the same but means nothing to assistive technology. - The bold and centered look is just a default. Change it with CSS, for example
th { text-align: left; }. - Put the header row inside
<thead>, so it can repeat on every printed page.
HTML <th> Tag exercises
Add header cells
Make a table with one row of two heading cells: Name and Role.
Result
