- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <thead> Tag
HTML Tags
HTML <thead> Tag
The thead tag groups the header rows of a table, the row with the column names. It goes first in the table, before tbody, and it is what browsers repeat at the top of every printed page of a long table.
Together with tbody and tfoot, it divides a table into header, body and footer. The header cells inside are usually th cells.
Syntax
html
<table>
<thead>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</tbody>
</table>It has no attributes of its own, only the global ones such as class, id and style.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thead Tag Example</title>
<style>
table {
border-collapse: collapse;
width: 70%;
margin: 20px auto;
text-align: center;
}
thead {
background-color: #29AB87;
color: white;
}
th, td {
border: 1px solid #555;
padding: 10px;
}
tbody tr:nth-child(even) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<h2>HTML Table with Thead Example</h2>
<table>
<thead>
<tr>
<th>Planet</th>
<th>Distance from Sun</th>
<th>Moons</th>
</tr>
</thead>
<tbody>
<tr>
<td>Mercury</td>
<td>57.9 million km</td>
<td>0</td>
</tr>
<tr>
<td>Earth</td>
<td>149.6 million km</td>
<td>1</td>
</tr>
<tr>
<td>Jupiter</td>
<td>778.5 million km</td>
<td>79</td>
</tr>
</tbody>
</table>
</body>
</html>The table of planets has a green header row with "Planet", "Distance from Sun" and "Moons". That row is inside <thead>, so the CSS can style it separately from the data.
Why bother with thead
- Styling:
thead th { background: #e2e8f0; }targets only the header, without extra classes. - Printing: long tables repeat the header on each page.
- Sticky headers:
thead th { position: sticky; top: 0; }keeps column names visible while scrolling a long table. - Scripts: table sorting and filtering libraries look for
<thead>to know which row holds the labels.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
HTML <thead> Tag exercises
Group the header row
Make a table whose head holds one row of headings: Name and Role.
Result
Check your answer to see it here.
