The HTML <thead> tag defines the header section of a table, grouping the top rows that contain column headings. It helps organize table data by separating header content from the rest of the table.
- Placed inside a <table> and contains <tr> and <th> elements.
- Separates header rows from <tbody> and <tfoot>.
- Improves table structure, readability, and accessibility.
Syntax:
<thead>
// Table head Contents...
</thead>
Attributes
- align: The align attribute sets the horizontal alignment of the text content.
- valign: The valign attribute sets the vertical alignment of the text content.
- char: The char attribute aligns content based on a specific character.
- charoff: The charoff attribute specifies the offset (number of characters) from the alignment character.
Note:
- The <thead> tag also supports the Global Attributes and Event Attributes in HTML.
- The attribute values used with <thead> are deprecated in the HTML5.
Example: The content within <thead> includes labels for each column, for better representation of table data.
<!DOCTYPE html>
<html>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h2>thead Tag</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>User Id</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ron</td>
<td>@ron_b</td>
</tr>
<tr>
<td>Harry</td>
<td>@harry</td>
</tr>
</tbody>
</table>
</center>
</body>
</html>