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

label

Associates a text caption with a form control. Labels are essential for accessibility, enabling screen readers to announce form fields and allowing users to click the label to focus the associated input.

When to Use

  • Every input, select, and textarea needs a label
  • Checkboxes and radio buttons should have labels wrapping them
  • Any form control that requires user identification

Always provide labels. Forms without labels are inaccessible to screen reader users.

VB Styling

Vanilla Breeze styles labels as display: block with font-weight: 500 and a small bottom margin (var(--size-xs)). When a label contains a checkbox or radio input, VB auto-detects this via :has() and switches to inline-flex with first-baseline alignment (the control lines up with the first line of text, even when the text wraps), gap spacing, a 24px minimum row height and a pointer cursor — no classes needed.

Association Methods

Explicit: Using the for Attribute

The recommended method. The label's for attribute matches the input's id.

Implicit: Wrapping the Input

The label wraps the input. Useful for checkboxes and radios where text follows the control.

With Checkboxes and Radios

For checkboxes and radio buttons, wrap the input inside the label. VB auto-detects the contained checkbox or radio via label:has(input[type="checkbox"]) and switches the label to inline-flex with proper alignment and a pointer cursor. No extra classes required.

Checkbox and radio labels are inline-flex, so without a wrapper they sit side by side in one row. Wrap them in <layout-stack> to stack them.

Required Field Indicator

Inside <form-field>, the asterisk is automatic. When the field contains a required control, form-field adds a red * after the label (and after the legend of a grouped field). Screen readers do not announce the asterisk, because the control's native required state is announced instead. Keep the label text plain. A typed * would show twice and be read aloud as “star”. Explain the asterisk once at the top of the form.

A bare label outside form-field gets no marker. Add your own, hidden from screen readers, and keep required on the control: <label for="name">Name <span aria-hidden="true">*</span></label>.

Visually Hidden Labels

When a label is not visually needed (e.g., a search field with a placeholder), hide it visually but keep it accessible with the .visually-hidden utility class.

The .visually-hidden class hides the label from sight while keeping it announced by screen readers.

Enhanced Labels

  • data-floating-label on <form-field> places the label inside the control and floats it up when the field has focus or a value
  • <form-field> adds the silent required asterisk, hint and error messages around a label/control pair

Accessibility Notes

  • Every input needs a label: No exceptions for accessibility
  • Use for attribute: Explicit association is clearer and more robust than wrapping
  • Labels are clickable: Clicking a label focuses its associated input
  • Don't use placeholder as label: Placeholders disappear when typing
  • One label per input: A single label cannot serve multiple inputs
  • aria-labelledby alternative: Can reference multiple elements for complex labels

CSS Reference

Related

↑