tr
The tr element defines a row of cells in a table. It can contain header cells (th) and/or data cells (td) and must be a direct child of thead, tbody, or tfoot.
Description
The <tr> (table row) element is a container for a horizontal group of cells. Each row must contain at least one <th> or <td> element, and all rows in a table should have the same number of cells (accounting for colspan).
Vanilla Breeze applies hover effects to rows within <tbody> to help users track data across columns.
When to Use
- Every table row: All rows of data, headers, and footers require tr elements
- Grouping cells: Each horizontal set of related data goes in one row
- Header rows: In thead, rows typically contain th elements
- Data rows: In tbody, rows typically contain td elements (with optional th for row headers)
Basic Example
Rows contain cells that align with the table's column structure.
| Name | Role | Location |
|---|---|---|
| Alice Johnson | Developer | New York |
| Bob Smith | Designer | San Francisco |
| Carol Williams | Manager | Chicago |
Rows with Row Headers
Use <th scope="row"> in data rows to identify row headers.
| Feature | Basic | Pro | Enterprise |
|---|---|---|---|
| Storage | 5 GB | 50 GB | Unlimited |
| Users | 1 | 10 | Unlimited |
| Support | Priority | 24/7 Phone | |
| API Access | No | Yes | Yes |
Row Hover Effect
Rows in tbody receive a hover effect to help users track data horizontally.
| Product | Category | Price | Stock |
|---|---|---|---|
| Laptop Stand | Accessories | $49.99 | 125 |
| Wireless Mouse | Peripherals | $29.99 | 340 |
| USB-C Hub | Accessories | $39.99 | 78 |
| Monitor Arm | Furniture | $89.99 | 45 |
Rows with Spanning Cells
Use colspan and rowspan attributes on cells to span multiple columns or rows.
| Time | Monday | Tuesday | Wednesday |
|---|---|---|---|
| 9:00 | Team Meeting | Planning | Code Review |
| 10:00 | All-Hands Meeting | ||
| 11:00 | Development | Development | Development |
Group Header Rows
Rows can serve as group headers within tbody sections.
| Product | Price | Stock |
|---|---|---|
| Electronics | ||
| Wireless Mouse | $29.99 | 150 |
| USB-C Hub | $39.99 | 75 |
| Furniture | ||
| Monitor Stand | $49.99 | 45 |
| Desk Organizer | $24.99 | 120 |
Accessibility
- Consistent cell count: All rows should have the same number of cells (accounting for colspan)
- Row headers: Use
<th scope="row">when the first cell identifies the row - Screen reader navigation: Users can navigate row by row through table data
- Implicit role: tr has an implicit ARIA role of
row
JavaScript Interaction
Common operations with table rows:
Valid Parent Elements
The tr element must be a child of one of these elements:
| Parent | Purpose | Typical Content |
|---|---|---|
<thead> |
Header rows | <th scope="col"> cells |
<tbody> |
Data rows | <td> and optional <th scope="row"> |
<tfoot> |
Footer/summary rows | <td> cells with totals/summaries |