<tbody> groups a table’s body rows. It separates data from heading and footer rows and gives CSS or scripts a clear place to target them.
Group the data
Only the two workshop rows are in <tbody>. Header and total rows remain in their own groups.
HTML and CSS
HTML
<table>
<caption>
Workshop registrations
</caption>
<thead>
<tr>
<th scope="col">Workshop</th>
<th scope="col">Places booked</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">HTML basics</th>
<td class="amount">12</td>
</tr>
<tr>
<th scope="row">CSS layout</th>
<td class="amount">8</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="row">Total</th>
<td class="amount">20</td>
</tr>
</tfoot>
</table>
CSS
/* Presentation: these styles make the table easier to read. */
table {
border-collapse: collapse;
}
caption {
text-align: left;
font-weight: bold;
margin-bottom: 0.5rem;
}
th,
td {
border: 1px solid #94a3b8;
padding: 0.5rem 0.75rem;
text-align: left;
}
.amount {
text-align: right;
font-variant-numeric: tabular-nums;
}
Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.
Multiple groups and implicit markup
A table may contain several consecutive <tbody> groups, such as one per department. Each contains <tr> rows. Rowspans stay within a row group; do not attempt to span from one <tbody> into another.
If you write direct <tr> children in HTML source, the parser normally inserts <tbody> in the DOM. As a result, table > tr can fail even though the source looks like it should match. Write explicit groups and use tbody > tr when targeting body rows.
Accessibility and alternatives
A body group organizes rows, but it does not name every group or replace <th> associations. Use row headers, clear column headings, and a caption. Do not add redundant roles to native table structure.
Add tbody tr:hover { background: #eff6ff; } as a visual aid. Keep text and header structure readable without the hover color; touch and keyboard users may never see it.
Sources and browser support
MDN: tbody describes the syntax and links to the specification and compatibility data. Check individual values in that table when supporting older browsers.