Label
A form label.
For a field
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export default function LabelForAField() {
return (
<div className="grid w-full max-w-xs gap-2">
<Label htmlFor="label-invoice-number">Invoice number</Label>
<Input id="label-invoice-number" defaultValue="INV-2041" />
</div>
)
}
Around a control
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label"
export default function LabelAroundAControl() {
return (
<Label>
<Checkbox defaultChecked />
Send a copy to the project owner
</Label>
)
}
Disabled
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export default function LabelDisabled() {
return (
<div className="group grid w-full max-w-xs gap-2" data-disabled="true">
<Label htmlFor="label-tax-number">Tax number</Label>
<Input id="label-tax-number" defaultValue="Set by the workspace owner" disabled />
</div>
)
}
Installation
npx shadcn@latest add @khaeli/labelbunx --bun shadcn@latest add @khaeli/labelInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
Accessible name
htmlForis theidof the control. The label's text becomes the control's name, and a click on the label focuses or toggles the control.- A label may wrap its control instead: the text beside the control names it, and no
idis needed. - One label per control. Text that explains the value belongs in a description that the control lists in
aria-describedby. - The label dims with its field when an ancestor with the class
groupcarriesdata-disabled="true". Disable the control itself as well: the dimming is only visual.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/label.json