Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

th

The th element defines a header cell in a table. Vanilla Breeze styles headers with a raised background and semi-bold weight. Always use scope for accessibility. Supports sort indicators and numeric alignment via data attributes.

Description

The <th> (table header) element defines a cell that acts as a header for a group of table cells. Headers can apply to columns, rows, or groups of either.

Vanilla Breeze gives every header cell a semi-bold font weight (600). Column headers (in <thead>, or with scope="col" / scope="colgroup") also get a raised background (var(--color-surface-raised)) and a thicker bottom border (var(--border-width-medium)). Row headers (<th scope="row"> in <tbody>) keep the data-cell look, a transparent background and a thin rule, so row hover, stripe and selection tints run across the whole row.

When to Use

  • Column headers: In <thead> rows with scope="col"
  • Row headers: First cell of data rows with scope="row"
  • Group headers: Headers spanning multiple columns/rows with scope="colgroup" or scope="rowgroup"

When to Use td Instead

  • Data cells: Cells containing actual data values
  • Summary cells: Totals in <tfoot> (though the label cell may be <th>)

The scope Attribute

The scope attribute is essential for accessibility. It tells assistive technologies which cells the header applies to. Always include it.

Value Description Use Case
col Header applies to all cells in the column Column headers in <thead>
row Header applies to all cells in the row Row headers in first cell of <tbody> rows
colgroup Header applies to multiple columns Group headers used with colspan
rowgroup Header applies to multiple rows Section headers spanning all columns

Examples

Column and Row Headers

This example shows both scope="col" for column headers and scope="row" for row headers. Screen readers use these to announce context when navigating cells.

Column Group Headers

Use scope="colgroup" with colspan for headers that span multiple columns, commonly seen in multi-level header rows. Pair it with real <colgroup span> elements so the group the header covers is defined in the markup.

Row Group Headers

Use scope="rowgroup" for section headers that apply to multiple rows within a group.

Basic Table

A standard table showing headers in context with data rows.

Sortable Headers

data-sort on a <th> is read by two different enhancements, and it means a different thing to each:

Used with data-sort means Sort type from Cell value override
<data-table> The sort type: string, number or date data-sort itself data-sort-value on the <td>
table[data-sortable] The column key (any name) data-sort-type="text|number|date" on the <th> data-sort-value (or data-value) on the <td>

Either way the behaviour follows the APG sortable table: the <th> keeps its columnheader role and carries aria-sort, and the script wraps the header text in a native <button data-sort-button> that takes focus and Enter/Space. VB styles that button to read as header text with a focus ring, and draws the direction glyph (⇅, ↑, ↓) from aria-sort, so the visual and accessible state cannot drift.

A bare <th data-sort> without either enhancement has no behaviour, so VB draws no sort affordance on it. On a server-sorted static table you can still mark the sorted column with aria-sort="ascending" or "descending"; VB shows the matching arrow.

Numeric and Alignment Attributes

data-numeric

Use data-numeric on header cells for numeric columns. This aligns the header text to the inline end (right in left-to-right text, left in right-to-left) and applies font-variant-numeric: tabular-nums for proper digit alignment.

data-align

Use data-align for explicit text alignment when the default (start) or data-numeric (end) are not appropriate.

VB Data Attributes

Attribute Values Description
data-numeric Boolean attribute Aligns content to the inline end (right in LTR, left in RTL) and uses tabular numerals
data-align start, center, end Explicit text alignment override
data-sort <data-table>: string, number, date; [data-sortable]: a column key Marks a sortable column; see Sortable Headers for the two meanings

Standard HTML Attributes

Attribute Values Description
scope col, row, colgroup, rowgroup Specifies which cells the header applies to (required for a11y)
colspan Positive integer Number of columns the header spans
rowspan Positive integer Number of rows the header spans
abbr String Abbreviated version of header content for screen readers

CSS Reference

Accessibility

  • Always use scope: The scope attribute is essential for screen readers to associate headers with data cells
  • Screen reader announcement: When navigating to a data cell, the associated headers are announced
  • Complex tables: For tables with multiple header levels, consider using the headers attribute on <td> elements
  • Implicit roles: <th> has an implicit ARIA role of columnheader (with scope="col") or rowheader (with scope="row")
  • Sort state: When a column is sorted, use aria-sort="ascending" or aria-sort="descending" on the <th>. Never give the <th> itself role="button": that replaces the columnheader role, aria-sort is then ignored, and the column's cells lose their header. Put a <button> inside the header instead.

Related

  • <td> - Data cells (th provides headers for)
  • <tr> - Table rows containing th cells
  • <thead> - Primary location for column headers
  • <tbody> - Contains row headers with scope="row"
  • <table> - The table container
  • <data-table> - Interactive table component that uses sort attributes on <th>
↑