The HTML <tbody> tag defines the body section of a table, grouping the main data rows separately from the header and footer.
- Placed inside a <table> and contains <tr> (table rows) with <td> (data cells).
- Separates table data from <thead> (header) and <tfoot> (footer).
- Improves table structure, readability, and accessibility.
Syntax:
<tbody> // Table contents </tbody>Attributes
- align: The align attribute sets the horizontal alignment of the content.
- valign: The valign attribute sets the vertical alignment of the content.
- char: The char attribute aligns content based on a specific character.
- charoff: The charoff attribute specifies the offset from the alignment character.
Note: These attributes were supported in HTML 4.01 but are not supported in HTML5.
Example: Using the <tbody> tag to group the body content of an HTML table. It contains rows with data for "Shashank" and "GeeksforGeeks" under "Name" and "User Id."
<!DOCTYPE html>
<html>
<head>
<title>HTML tbody Tag</title>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h2>tbody Tag</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>User Id</th>
</tr>
</thead>
<!-- tbody tag starts from here -->
<tbody>
<tr>
<td>Shashank</td>
<td>@shashankla</td>
</tr>
<tr>
<td>GeeksforGeeks</td>
<td>@geeks</td>
</tr>
</tbody>
<!-- tbody tag ends here -->
</table>
</center>
</body>
</html>