The thead tag
The thead
tag defines the top of the table. It is used to group rows so that CSS styles can be applied to a group at once. There can only be one thead
tag in one table.
The thead
tag is often used in conjunction with tbody
and tfoot
to define the header, body, and footer of an HTML table.
Example
Let's add red text color to the group of rows united by the thead
tag using the color
property:
<table>
<thead>
<tr>
<th>Name</th>
<th>Surn</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>name1</td>
<td>surn1</td>
<td>200$</td>
</tr>
<tr>
<td>name2</td>
<td>surn2</td>
<td>1000$</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>count: 2</td>
<td>-</td>
<td>total: 1200$</td>
</tr>
</tfoot>
</table>
thead {
color: red;
}
table, td, th {
border: 1px solid black;
}
:
Example
And here thead
is not on top, and tfoot
is not on the bottom, nevertheless the browser will put them in their places:
<table>
<tfoot>
<tr>
<td>count: 2</td>
<td>-</td>
<td>total: 1200$</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>name1</td>
<td>surn1</td>
<td>200$</td>
</tr>
<tr>
<td>name2</td>
<td>surn2</td>
<td>1000$</td>
</tr>
</tbody>
<thead>
<tr>
<th>Name</th>
<th>Surn</th>
<th>Salary</th>
</tr>
</thead>
</table>
table, td, th {
border: 1px solid black;
}
: