thead

The thead element groups header rows in a table. Vanilla Breeze styles it with a raised background and a medium bottom border to visually separate column headers from data.

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> header cells with a raised background (var(--color-surface-raised)) and a thicker bottom border (var(--border-width-medium)) 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: Use data-sticky="header" on the table so headers remain visible while scrolling

Examples

Basic Table with thead

A complete table using thead with <th scope="col"> for column headers, alongside <tbody> and <tfoot>.

Sticky Header

Add data-sticky="header" to the <table> element so the header row stays visible as the user scrolls through long tables. VB applies position: sticky, inset-block-start: 0, and z-index: 1 to the thead th cells.

Scope Attribute

The scope attribute on <th> tells assistive technologies which cells the header relates to. See the shared demo for headers using scope="col" and scope="row".

CSS Reference

Vanilla Breeze applies these styles to <th> elements within thead:

Property Value Purpose
background var(--color-surface-raised) Subtle background to distinguish headers from data
border-block-end var(--border-width-medium) solid var(--color-border) Thicker border separating header from body
position: sticky Via data-sticky="header" Header stays fixed at the top when scrolling
z-index 1 Ensures sticky header paints above body rows

Accessibility

  • Structural grouping: Helps assistive technologies distinguish header rows from data rows
  • Always use scope: Set scope="col" on each <th> inside thead so screen readers announce the header for each column
  • Grouped headers: Use scope="colgroup" with colspan for multi-column header groups
  • Implicit role: thead has an implicit ARIA role of rowgroup
  • Repeated headers: When printing, thead content can repeat on each page

Related

  • <table> - Parent container for thead
  • <tr> - Table rows within thead
  • <th> - Header cells (always use in thead with scope)
  • <tbody> - Data row group (follows thead)
  • <tfoot> - Footer row group for summaries and totals
  • <data-table> - Enhanced table component with sorting, filtering, and pagination