Label
A minimal label component for form fields with optional required indicator.
Basic Usage
Required Indicator
Displays a red asterisk (*) using the --color-wk-danger-text CSS variable. The asterisk includes aria-hidden="true" since it is purely decorative.
Narrow Column — Label Above Field
When the form lives in a sidebar, modal, or mobile-narrow column, place the label directly above the input. The label inherits the input's full width without competing for horizontal space. This is the default layout used by <x-wirekit::input label="…"> and every other WireKit form component when you pass the label prop.
Horizontal Form — Inputs Aligned on a Vertical Line
For wider forms (settings pages, billing-address screens), pair each label with its input on a single row and pin the labels to a fixed-width column so every input starts at the same horizontal position. CSS Grid with grid-template-columns: <label-col> 1fr keeps the alignment robust across long labels and varying input widths:
The 9rem label column is the smallest width that holds the longest label (Street & number) without wrapping; raise to 10–12rem if your form has longer field names. Switch to a single-column stack on narrow viewports with @media (max-width: 480px) { form { grid-template-columns: 1fr; } } so the labels don't get cramped — the same layout collapses gracefully to the stacked pattern shown above.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
for |
string|null | null |
The id of the associated form element |
required |
bool | false |
Shows a required indicator (*) |
scope |
string|null | null |
Scoped personalization name |
Accessibility
The label component renders a native <label> element — the most important accessibility primitive for form fields.
forattribute — Always set theforprop to theidof the associated input. This creates a programmatic association so screen readers announce the label when the input receives focus, and clicking the label focuses the input.- Required indicator — The red asterisk (
*) includesaria-hidden="true"because it is purely visual. Screen readers should not announce "asterisk" — instead, mark required fields with the nativerequiredattribute on the input itself, which assistive technology announces as "required". - Implicit vs. explicit labeling — WireKit form components (Input, Textarea, Select, etc.) handle labeling automatically when you pass the
labelprop — they render<x-wirekit::label for="{id}">internally. Use the standalone Label component only when building custom form layouts.
Keyboard Interaction
This component is purely presentational and does not respond to keyboard input.
Design Tokens
| Token | Used for |
|---|---|
--font-wk-sans |
Label font family |
--font-wk-body-weight |
Label font weight |
--font-wk-letter-spacing |
Letter spacing |
--text-wk-md |
Label font size |
--color-wk-text |
Label text |
--color-wk-danger-text |
Required indicator (*) |
Further Reading
- MDN:
<label>element - MDN: Labels and form controls
- WebAIM: Form Labels — accessibility guidance