Label accessibility
WCAG 2.1 AA requirements
Semantics
- Renders a native
<label>element. When linked viahtmlFor, screen readers announce the label text as the input's accessible name. - The
<label>also makes the text a click target that focuses the associated input.
Required indicator
- The red asterisk from
requiredis wrapped inaria-hiddenso screen readers do not announce "star" or "asterisk". - The asterisk is a visual cue only. Always set
aria-requiredon the input element itself for assistive tech.
Peer-disabled styling
- When the paired input is disabled, the label automatically reduces opacity and changes the cursor via the
peer-disabledTailwind modifier. This requires the input to have thepeerclass (built into Checkbox and Switch).
Contrast
tone="default"usestext-foreground— full contrast.tone="muted"usestext-muted-foreground— verify it stays above 4.5:1 against the page background.tone="destructive"usestext-destructive— designed to meet contrast requirements.
Audit checklist
-
<label>element withhtmlFormatching the inputid - Required asterisk is
aria-hidden -
aria-requiredis on the input, not the label - Muted tone meets 4.5:1 contrast
- Clicking the label focuses the associated input