thead
The thead element groups the header row(s) of a table. It defines the column headers and is essential for table accessibility and proper structure.
Description
The <thead> element contains one or more <tr> elements that define the header row(s) of a table. It must appear after any <caption> or <colgroup> elements and before <tbody> and <tfoot>.
Vanilla Breeze styles thead with a raised background color and a thicker bottom border to visually separate headers from data rows.
When to Use
- Every data table: All tables with meaningful data should have thead to define column headers
- Multiple header rows: When columns have grouped headers or sub-headers
- Printed tables: Headers repeat on each page when printing long tables
- Sticky headers: Enables CSS position: sticky for headers that remain visible while scrolling
Basic Example
A thead typically contains a single row with <th> elements.
| Name | Department | Location | |
|---|---|---|---|
| Alice Johnson | Engineering | New York | alice@example.com |
| Bob Smith | Design | San Francisco | bob@example.com |
| Carol Williams | Marketing | Chicago | carol@example.com |
Multiple Header Rows
Use multiple rows in thead for grouped or hierarchical headers.
| Region | Q1 | Q2 | ||
|---|---|---|---|---|
| Revenue | Expenses | Revenue | Expenses | |
| North | $45,000 | $32,000 | $52,000 | $35,000 |
| South | $38,000 | $28,000 | $41,000 | $30,000 |
| East | $55,000 | $40,000 | $62,000 | $45,000 |
Sticky Headers
The thead element enables sticky positioning for headers that remain visible while scrolling through long tables.
| ID | Product | Price |
|---|---|---|
| 001 | Widget A | $19.99 |
| 002 | Widget B | $24.99 |
| 003 | Widget C | $29.99 |
| 004 | Widget D | $34.99 |
| 005 | Widget E | $39.99 |
| 006 | Widget F | $44.99 |
| 007 | Widget G | $49.99 |
| 008 | Widget H | $54.99 |
Accessibility
- Structural grouping: Helps assistive technologies distinguish header rows from data rows
- Use
<th>with scope: Always use<th scope="col">for column headers inside thead - Screen reader navigation: Users can navigate directly to the header section of a table
- Repeated headers: When printing, thead content can repeat on each page
Scope Values for thead
| Scope Value | Use in thead | Description |
|---|---|---|
col |
Common | Header applies to all cells in the column |
colgroup |
Grouped headers | Header applies to multiple columns (use with colspan) |
row |
Rare | Generally not used in thead |
Styling
Vanilla Breeze applies these styles to th elements within thead:
| Property | Value | Purpose |
|---|---|---|
background |
var(--color-surface-raised) |
Subtle background to distinguish from data |
font-weight |
600 |
Semi-bold for emphasis |
border-block-end |
var(--border-width-medium) |
Thicker border separating header from body |