Forms
Label
Visible name for a form control, set in body size with medium weight. Clicking it focuses or toggles the control.
import { Label } from '@statix/ui/label';Playground
<Label>Email</Label>Examples
Above a field
Point for at the id of the control.
<script lang="ts">
import { Input } from '@statix/ui/input';
import { Label } from '@statix/ui/label';
</script>
<div class="flex w-full max-w-sm flex-col gap-2">
<Label for="label-name">Full name</Label>
<Input id="label-name" autocomplete="name" value="Anna Berger" />
</div>Next to a checkbox
Use font-normal when the label is a sentence next to a checkbox or switch.
<script lang="ts">
import { Checkbox } from '@statix/ui/checkbox';
import { Label } from '@statix/ui/label';
</script>
<div class="flex items-center gap-3">
<Checkbox id="label-terms" />
<Label for="label-terms" class="font-normal">I accept the terms of the hosting contract</Label>
</div>Optional fields
Mark the few optional fields instead of every required one.
<script lang="ts">
import { Input } from '@statix/ui/input';
import { Label } from '@statix/ui/label';
</script>
<div class="flex w-full max-w-sm flex-col gap-2">
<Label for="label-company">
Company
<span class="font-normal text-muted-foreground">(optional)</span>
</Label>
<Input id="label-company" autocomplete="organization" placeholder="Yoga Berger GmbH" />
</div>Guidelines
Do
- Keep labels short and specific: "Phone", not "Please enter your phone number".
- Mark optional fields with "(optional)" in muted text.
Don't
- Don't end labels with a colon.
- Don't put the label inside the field as a placeholder.
Accessibility
- Renders a <label>. With for set to the control id, screen readers announce the label and clicks reach the control.
- Inside a Field use FieldLabel, which adds the field layout on top of Label.
- Fades to 50% when the control next to it (peer) or the surrounding field is disabled.
API reference
Label
renders<label> and accepts its attributes| Prop | Type | Default |
|---|---|---|
for | string id of the control this label names. | – |
ref bind | HTMLLabelElement | null The rendered element. | – |
class | ClassValue Merged with the default classes; yours win. | – |
| Data attribute | Meaning |
|---|---|
data-slot="label" | Always present. |