tr
The tr element defines a row of cells in a table. Vanilla Breeze adds data attributes for row states like selection, highlighting, and expandable detail rows.
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> and provides data attributes for common row states: selection, highlighting, disabling, and expandable detail rows.
When to Use
Examples
Basic Table Rows
Rows contain cells that align with the table's column structure. Hover over rows to see the built-in highlight effect.
<table> <caption>Team Members</caption> <thead> <tr> <th scope="col">Name</th> <th scope="col">Role</th> <th scope="col">Location</th> </tr> </thead> <tbody> <tr> <td>Alice Johnson</td> <td>Developer</td> <td>New York</td> </tr> <tr> <td>Bob Smith</td> <td>Designer</td> <td>San Francisco</td> </tr> </tbody></table>
Row States
Vanilla Breeze provides data attributes for common row states. These work with both static tables and the <data-table> component.
<tbody> <!-- Selected row --> <tr data-selected> <td>Alice Johnson</td> <td>Developer</td> <td>New York</td> </tr> <!-- Highlighted row --> <tr data-highlight> <td>Bob Smith</td> <td>Designer</td> <td>San Francisco</td> </tr> <!-- Disabled row --> <tr data-disabled> <td>Carol Williams</td> <td>Manager</td> <td>Chicago</td> </tr></tbody>
Row Hover Effect
Rows in <tbody> receive a hover effect automatically to help users track data across columns. This is applied by default in Vanilla Breeze and requires no additional attributes.
/* Vanilla Breeze default — applied automatically */tbody tr:hover { background: var(--color-surface-raised);}
Selectable Rows
Add data-selectable to indicate a row can be selected. Combine with data-selected to mark the current selection. The <data-table> component manages selection state automatically.
<tbody> <tr data-selectable> <td>Row 1 — click to select</td> <td data-numeric>$49.99</td> </tr> <tr data-selectable data-selected> <td>Row 2 — already selected</td> <td data-numeric>$29.99</td> </tr></tbody>
Expandable Rows
Use data-expandable on the trigger row and data-state-expanded or data-state-hidden on the detail row. Detail rows are typically full-width with colspan.
<tbody> <tr data-expandable> <td>Order #1024</td> <td data-numeric>$149.99</td> <td>Shipped</td> </tr> <tr data-state-expanded> <td colspan="3"> Tracking: 1Z999AA10123456784 </td> </tr> <tr data-expandable> <td>Order #1025</td> <td data-numeric>$89.50</td> <td>Processing</td> </tr> <tr data-state-hidden> <td colspan="3"> Estimated delivery: March 15, 2026 </td> </tr></tbody>
VB Data Attributes
| Attribute | Purpose | Applied To |
|---|---|---|
data-selected |
Marks a row as selected (primary subtle background + outline) | <tr> in <tbody> |
data-disabled |
Reduces opacity and disables pointer events | <tr> in <tbody> |
data-highlight |
Applies a warning-subtle background highlight | <tr> in <tbody> |
data-selectable |
Indicates the row is interactive and can be selected | <tr> in <tbody> |
data-expandable |
Marks a row as having an expandable detail row | <tr> in <tbody> |
data-state-hidden |
Hides a detail row (display: none) |
<tr> detail row |
data-state-expanded |
Shows a detail row with a sunken background | <tr> detail row |
CSS Reference
/* Row state styling */tr[data-selected] { background: var(--color-primary-subtle); outline: var(--border-width-thin) solid var(--color-primary);} tr[data-highlight] { background: var(--color-warning-subtle);} tr[data-disabled] { opacity: 0.5; pointer-events: none;} tr[data-state-hidden] { display: none;} tr[data-state-expanded] { background: var(--color-surface-sunken);}
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 |
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 ofrow - Disabled rows: When using
data-disabled, also addaria-disabled="true"for assistive technology - Selected rows: When using
data-selected, also addaria-selected="true"for assistive technology