Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

Can we have multiple <tbody> tags in same <table>? If yes then in what scenarios should we use multiple <tbody> tags?

1 Answer

0 votes
by (40.7k points)

You can use multiple <tbody> tags in the same table, to more easily style groups of data, like this:

thead th { width: 100px; border-bottom: solid 1px #ddd; font-weight: bold; }

tbody:nth-child(odd) { background: #f5f5f5;  border: solid 1px #ddd; }

tbody:nth-child(even) { background: #e5e5e5;  border: solid 1px #ddd; }

<table>

    <thead>

        <tr><th>Customer</th><th>Order</th><th>Month</th></tr>

    </thead>

    <tbody>

        <tr><td>Customer 1</td><td>#1</td><td>January</td></tr>

        <tr><td>Customer 1</td><td>#2</td><td>April</td></tr>

        <tr><td>Customer 1</td><td>#3</td><td>March</td></tr>

    </tbody>

    <tbody>

        <tr><td>Customer 2</td><td>#1</td><td>January</td></tr>

        <tr><td>Customer 2</td><td>#2</td><td>April</td></tr>

        <tr><td>Customer 2</td><td>#3</td><td>March</td></tr>

    </tbody>

    <tbody>

        <tr><td>Customer 3</td><td>#1</td><td>January</td></tr>

        <tr><td>Customer 3</td><td>#2</td><td>April</td></tr>

        <tr><td>Customer 3</td><td>#3</td><td>March</td></tr>

    </tbody>

</table>

This will only work in newer browsers, you can use the grouping for JavaScript, etc. It's a convenient way to visually group the rows to make the data much more readable. 

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Aug 26, 2019 in BI by Vaibhav Ameta (17.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...