A semantic <label> element used to associate text with a form control.
import { Label } from '@bgunnarsson/react-primitives'Extends React.LabelHTMLAttributes<HTMLLabelElement>.
| Prop | Type | Default | Description |
|---|---|---|---|
htmlFor |
string |
— | The id of the associated form control. Clicking the label focuses the input. |
children |
React.ReactNode |
— | Label text or content. |
<Label htmlFor="email">Email address</Label>
<Input id="email" type="email" />{/* Standard form label */}
<Label htmlFor="username" className="text-sm font-medium text-gray-700">
Username
</Label>
{/* Required field indicator */}
<Label htmlFor="email" className="text-sm font-medium text-gray-700">
Email address <span className="text-red-500">*</span>
</Label>
{/* Paired with Checkbox */}
<div className="flex items-center gap-2">
<Checkbox id="terms" />
<Label htmlFor="terms" className="text-sm text-gray-700 cursor-pointer">
I agree to the terms and conditions
</Label>
</div>
{/* Paired with Switch */}
<div className="flex items-center gap-3">
<Switch id="notifications" />
<Label htmlFor="notifications" className="text-sm font-medium text-gray-900 cursor-pointer">
Enable notifications
</Label>
</div>
{/* Disabled label */}
<Label htmlFor="disabled-input" className="text-sm font-medium text-gray-400 cursor-not-allowed">
Disabled field
</Label>- Always pair
Labelwith a form control usinghtmlFormatching the control'sid. This is required for screen reader accessibility and improves the click target size for mouse users. - When using
FormFieldandFormLabel, thehtmlFor/idwiring is handled automatically — useLabeldirectly only outside of the Form system.