Problem Statement
Which tag is used to group the main content rows of a table?
Explanation
The tbody tag is used to group the main content rows of a table. It contains the primary data rows, excluding headers and footers. The tbody tag wraps multiple tr tags that contain the actual table data. Using tbody provides semantic structure to your table. It clearly separates the body content from headers in thead and summaries in tfoot. This separation allows for independent styling of each section using CSS. For accessibility, screen readers can use these sections to help users navigate large tables more efficiently. The tbody tag is technically optional. If you do not include it, browsers will automatically wrap your data rows in an implied tbody. However, explicitly including tbody is a best practice for clear, maintainable code. You can have multiple tbody elements in one table to group related rows together.
Code Solution
SolutionRead Only
<!-- Table with tbody -->
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Laptop</td>
<td>$999</td>
</tr>
<tr>
<td>Mouse</td>
<td>$25</td>
</tr>
<tr>
<td>Keyboard</td>
<td>$75</td>
</tr>
</tbody>
</table>
<!-- Multiple tbody for grouping -->
<table>
<tbody>
<tr>
<td colspan="2"><strong>Q1 Sales</strong></td>
</tr>
<tr>
<td>January</td>
<td>$5,000</td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="2"><strong>Q2 Sales</strong></td>
</tr>
<tr>
<td>April</td>
<td>$6,000</td>
</tr>
</tbody>
</table>