What is the <tbody> element in HTML?
The <tbody> tag stands for table body. In HTML, there are three parts of a table (<table> tag): header, body, and footer. The <tbody> tag is used to define the body.
The <tbody> tag consists of all the rows (<tr> tag) and their respective child tags that are to be shown in the table. It is used to group the rows of the entire table.
The
<tr>tag is used to create a single row in the table. The<td>and<th>tags create standard data cells and heading cells in a row, respectively. The row defined by the<tr>tag is divided into cells according to the number of<td>or<th>tags used.
The <tbody> tag must be used inside the <table> tag and must contain one or more <tr> tags inside it.
Syntax
<table>
<tbody>
<tr/>
<tr/>
</tbody>
<table>
The above snippet of code provides the general and the most simple usage of the <tbody> tag. It can contain one or more child rows.
The <table> tag creates the table. The <tbody> tag must always be the child of the <table> tag, as shown. The body of the table can have multiple rows, and each row can have multiple children tags like <td> or <th>, etc.
More than one <tbody> tag can also be used inside a single <table> tag to divide the table into multiple sections.
Examples
In the above example, a simple table is created using the <table> tag. The header and footer are not defined in this case. Only the body of the table is defined with the <tbody> tag. This table mentions the name of a fruit and its quantity.
The <tr> tag defines a single row in the table in the above snippet. The <td> tag defines a single standard data cell in each row.
In the above example, we have used the <thead> tag to define the header of the table to make it more understandable.
We created a table using the <table> tag. The <thead> tag is used to define the header of the entire table. The <tr> tag defines a row and the <th> tag defines a heading in an individual cell.
In the <tbody> tag, there are two child rows and each row has three standard data cells (<td> tag).
Free Resources