HTML <tbody> Tag
The <tbody> tag defines the body content of an HTML table. It is used along with <thead> and <tfoot> elements. See examples.
The <tbody> tag defines the body content (a set of rows) of an HTML table creating a separate semantic block in it. The <tbody> tag is used along with the <thead> and the <tfoot> tags, which specify header and footer of the table respectively.
The <tbody> tag must be used as a child of the <table> element, after the <caption>, <colgroup> (if any) and the <thead> elements. In HTML5, the <tfoot> element comes either before or after the <tbody> element.
The <thead>, <tbody>, and <tfoot> elements do not affect the table layout by default. Use CSS properties to customize the look of the table.
When printing a document, the <thead> and <tfoot> elements will define the information that can be the same or very similar on each page of a multi-page table, while the content of the <tbody> tag will vary from page to page.
In case of using <tbody>, you can't have <tr> elements (table rows) which are children of the <table> element, but are not included within the <tbody>. If you use non-header and non-footer rows they must be inside of the <tbody> element.
More than one <tbody> elements can be used for each table as long as they are all successive. This will separate the rows in large tables into sections and you will be able to format each of them separately.
Syntax
The <tbody> tag comes in pairs. The content is written between the opening (<tbody>) and closing (</tbody>) tags.
HTML <tbody> Tag
<table>
<thead> ... </thead>
<tfoot> ... </tfoot>
<tbody>
<tr>
<td> ... </td>
</tr>
</tbody>
</table>Example of the HTML <tbody> tag:
HTML <tbody> Tag
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
th, td {
padding: 10px;
border: 1px solid #666;
}
</style>
</head>
<body>
<table style="width:80%; margin:30px auto; border-collapse:collapse;">
<thead style="background-color:#1c87c9; color:#fff;">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot style="background-color:grey;">
<!-- <tfoot> is placed after <thead>, but is shown on the bottom of the table. -->
<tr>
<td>Total</td>
<td>1500</td>
</tr>
</tfoot>
<tbody style="background-color:lightgrey;">
<tr>
<td>January</td>
<td>500</td>
</tr>
<tr>
<td>February</td>
<td>1000</td>
</tr>
</tbody>
</table>
</body>
</html>Result

Example of the HTML <tbody> tag with the <thead> and <tfoot> tags:
HTML <tbody> Tag
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
table {
width: 60%;
margin: 30px auto;
border-collapse: collapse;
}
thead {
background-color: #8ebf42;
color: #fff;
}
tbody {
background-color: #f3ebeb;
}
tfoot {
background-color: #ccc7c7;
}
th,
td {
padding: 10px;
border: 1px solid #666666;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>1500</td>
</tr>
<tr>
<td>February</td>
<td>1000</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>2500</td>
</tr>
</tfoot>
</table>
</body>
</html>Attributes
| Attribute | Values | Description |
|---|---|---|
| align | right left center justify char | Specifies the alignment of the content inside <tbody> element. Not supported in HTML5 |
| bgcolor | bgcolor | Sets the background color of the rows inside <tbody> element. Not supported in HTML5. |
| char | character | Specifies the alignment of the content inside the <tbody> element to a character. Is used only when the attribute align="char". Not supported in HTML5. |
| charoff | number | Specifies the number of characters the content inside the <tbody> element will be aligned from the character specified by the char attribute. Is used only when the attribute align="char". Not supported in HTML5. |
| valign | top bottom middle baseline | Specifies a vertical alignment of the content inside the <tbody>element. Not supported in HTML5. |
The <tbody> tag also supports the Global Attributes and the Event Attributes.
How to style an HTML <tbody> tag
{
"tag_name": "tbody"
}Practice
What is true about the HTML <tbody> tag according to the information provided on w3docs.com?