Skip to main content
WireKit
Copy for LLM

Label

A minimal label component for form fields with optional required indicator.

Basic Usage

A label bound to its input

Required Indicator

A required field, marked on the label

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.

Stacked label + input in a 16rem column

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:

Billing address — labels left, inputs aligned on a vertical line

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.

  • for attribute — Always set the for prop to the id of 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 (*) includes aria-hidden="true" because it is purely visual. Screen readers should not announce "asterisk" — instead, mark required fields with the native required attribute 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 label prop — 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

Was this page helpful?

Voting requires cookies or local storage. What we store