<tbody>

Draft

Definition

The <tbody> HTML element is used to group a set of table rows (<tr>) that make up the body or main content of a table. It is commonly used within the <table> element to enclose the rows that contain the actual data to be displayed.

Here’s an example of how to use the <tbody> element:

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
      <th>City</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John Doe</td>
      <td>30</td>
      <td>New York</td>
    </tr>
    <tr>
      <td>Jane Smith</td>
      <td>25</td>
      <td>London</td>
    </tr>
  </tbody>
</table>

In this example, the <tbody> element is used to group the two data rows (<tr>) that contain the actual content for the table. The table headers (<th>) are placed within the <thead> element, which represents the table header section.

By using the <tbody> element, you can logically separate the header and body sections of the table, improving the structure and organization of the tabular data. This can also be helpful for styling purposes or when manipulating the table content dynamically using JavaScript.

It’s worth mentioning that although it is not required to include a <tbody> element in every table, it is considered good practice to use it for better code organization and to ensure the table structure adheres to accessibility guidelines.

Related posts