GitHubGitHub
← All components
Forms / component

Label

A form label bound to a control by id, with an optional required marker that is announced as words rather than an asterisk.

DefaultRequired
<Label for="billing-email" required>Billing email</Label><TextInput id="billing-email" type="email" placeholder="ana@example.com" />

Installation

pnpm add @chanrg/4ui

Import the stylesheet once, at the root of your app:

import '@chanrg/4ui/styles.css';

Usage

import { Label, TextInput } from '@chanrg/4ui';<Label for="billing-email" required>Billing email</Label><TextInput id="billing-email" type="email" placeholder="ana@example.com" />

API reference

Props

PropTypeDefaultDescription
forstringid of the control this label names.
requiredbooleanfalseAdds the marker after the text.
requiredLabelstring'required'Accessible text behind the required marker.
childrenSnippetThe label text.

CSS variables

VariableDescription
--4ui-surfacePrimary component surface.
--4ui-textPrimary foreground color.
--4ui-borderDefault control and panel border.

Accessibility

  • A native <label>, so clicking the text focuses the control it names.
  • The asterisk is aria-hidden and paired with visually hidden text, so screen readers say “required” instead of “star”.
  • Use Field instead when you also need a description and an error wired to the control.

Dependencies

No runtime component dependencies.