tbody
The tbody element groups the body content (data rows) of a table. It contains the main data and enables row hover effects and striping variants.
Description
The <tbody> element contains one or more <tr> elements that make up the data portion of a table. It should appear after <thead> and before <tfoot> in the source order.
Vanilla Breeze applies row hover effects to tbody rows and uses tbody for the .striped variant's alternating background colors.
When to Use
- Every data table: All tables should use tbody to group data rows
- Multiple tbody sections: Group related rows for visual or semantic separation
- Dynamic content: Easier to target and update data rows separately from headers
- Scripting: JavaScript can easily target tbody for adding/removing rows
Basic Example
Wrap all data rows in a tbody element.
| SKU | Product | Category | Stock |
|---|---|---|---|
| A001 | Wireless Mouse | Peripherals | 45 |
| A002 | USB-C Hub | Accessories | 23 |
| A003 | Mechanical Keyboard | Peripherals | 18 |
| A004 | Monitor Stand | Furniture | 12 |
Row Hover Effect
Vanilla Breeze applies hover effects to rows within tbody, making it easier to track data across columns.
| Name | Role | Status |
|---|---|---|
| Alice Johnson | Developer | Active |
| Bob Smith | Designer | Active |
| Carol Williams | Manager | On Leave |
Multiple tbody Sections
Use multiple tbody elements to group related rows, creating visual sections within a single table.
| Item | Budget | Spent |
|---|---|---|
| Engineering | ||
| Software licenses | $12,000 | $10,500 |
| Hardware | $25,000 | $22,000 |
| Marketing | ||
| Advertising | $30,000 | $28,500 |
| Events | $15,000 | $14,200 |
| Operations | ||
| Facilities | $20,000 | $19,800 |
| Supplies | $5,000 | $4,200 |
Striped Variant
The .striped class on the table applies alternating backgrounds to tbody rows.
| ID | Name | Status |
|---|---|---|
| 001 | Project Alpha | Active |
| 002 | Project Beta | Planning |
| 003 | Project Gamma | Complete |
| 004 | Project Delta | On Hold |
| 005 | Project Epsilon | Active |
Accessibility
- Structural separation: Helps assistive technologies distinguish data from headers and footers
- Row navigation: Screen readers can navigate between different table sections
- Implicit role: tbody has an implicit ARIA role of
rowgroup - Use with th: When rows have headers, use
<th scope="row">in the first cell
JavaScript Interaction
The tbody element is useful for dynamic table manipulation.