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.
Association Methods
Using the for Attribute
The recommended method. The label's for attribute matches the input's id.
Code
Implicit Association (Wrapping)
The label wraps the input. Useful for checkboxes and radios where text follows the control.
Code
Label Placement
Above Input (Default)
Standard placement for text inputs. Easiest to scan.
Beside Input (Horizontal)
For checkboxes, radios, and compact forms.
Left of Input (Grid Layout)
In form.grid layout, labels appear to the left.
With Checkboxes and Radios
For checkboxes and radio buttons, wrap the input inside the label.
Checkboxes
Radio Buttons
Code
Required Field Indicator
Indicate required fields visually. The asterisk is commonly used but should be explained.
Code
Visually Hidden Labels
When a label is not visually needed (e.g., search with a placeholder), hide it visually but keep it accessible.
Code
The .visually-hidden class hides the label visually while keeping it accessible to screen readers.
With form-field
Labels work seamlessly with the form-field custom element.
Accessibility Notes
- Every input needs a label: No exceptions for accessibility
- Use
forattribute: Explicit association is clearer and more robust - Labels are clickable: Clicking a label focuses its associated input
- Don't use placeholder as label: Placeholders disappear when typing
- Multiple inputs per label: Not valid; use one label per input
- aria-labelledby alternative: Can reference multiple elements for complex labels