Open In App

Can I Add Multiple <tbody> Elements in Same Table in HTML ?

Improve
Improve
Like Article
Like
Save
Share
Report

Yes, we can add multiple <tbody> tags in a same table in HTML.

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 the 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.
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 the case of using <tbody>, you can’t have <tr> elements (table rows) that 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> element 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.

A <table> can have multiple <tbody> elements

Below is an example to demonstrate the same

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Title of the document</title>
      
    <style>
        table,
        table th,
        table td {
            border: 1px solid #c817175b;
        }
  
        thead th {
            width: 150px;
            border-bottom: solid 1px #15b74068;
            font-weight: bold;
        }
  
        tbody:nth-child(odd) {
            background: #0ce04f75;
            border: solid 1px #0000005f;
        }
  
        tbody:nth-child(even) {
            background: #10e14f61;
            border: solid 1px #00000050;
        }
  
        table {
            margin-left: auto;
            margin-right: auto;
        }
  
        h1 {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>Demostration for Multiple <tbody> tag</h1>
  
    <table>
        <thead>
            <tr>
                <th colspan="3">GeeksForGeeks</th>
            </tr>
            <tr>
                <th>Contest Name</th>
                <th>Year</th>
                <th>Article Published</th>
            </tr>
        </thead>
        <tbody align="center">
            <tr>
                <td>Technical Scripter </td>
                <td>2018</td>
                <td>934</td>
            </tr>
            <tr>
                <td>Technical Scripter</td>
                <td>2020</td>
                <td>2473</td>
            </tr>
            <tr>
                <td>Technical Scripter</td>
                <td>2022</td>
                <td>4048</td>
            </tr>
        </tbody>
        <tbody align="center">
  
            <tr>
                <td>Geeks-Premier-League</td>
                <td>2022</td>
                <td>2458</td>
            </tr>
            <tr>
                <td>TrueGeek</td>
                <td>2021</td>
                <td>139</td>
            </tr>
        </tbody>
        <tbody align="center">
            <tr>
                <td>ProGeek</td>
                <td>2019</td>
                <td>48</td>
            </tr>
            <tr>
                <td>ProGeeks2.0</td>
                <td>2020</td>
                <td>78</td>
            </tr>
            <tr>
                <td>ProGeek</td>
                <td>2021</td>
                <td>54</td>
            </tr>
        </tbody>
    </table>
</body>
  
</html>



 



Last Updated : 22 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads