Label
Renders an accessible label associated with controls.
Loading…
"use client"
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label"
export default function LabelDemo() {
return (
<div className="flex gap-2">
<Checkbox id="terms" />
<Label htmlFor="terms">Accept terms and conditions</Label>
</div>
)
}For form fields, use the Field component which includes built-in label, description, and error handling.
Installation
pnpm dlx shadcn@latest add @kickresume/labelUsage
import { Label } from "@/components/ui/label"<div className="flex gap-2">
<Checkbox id="terms" />
<Label htmlFor="terms">Accept terms and conditions</Label>
</div>Label in Field
For form fields, use the Field component which
includes built-in FieldLabel, FieldDescription, and FieldError components.
<Field>
<FieldLabel htmlFor="email">Your email address</FieldLabel>
<Input id="email" />
</Field>Loading…
"use client"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSeparator,
FieldSet,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
const months = [
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
]
const years = ["2024", "2025", "2026", "2027", "2028", "2029"]
const monthItems = [
{ label: "MM", value: null },
...months.map((month) => ({ label: month, value: month })),
]
const yearItems = [
{ label: "YYYY", value: null },
...years.map((year) => ({ label: year, value: year })),
]
export default function FieldDemo() {
return (
<div className="w-full max-w-md">
<form>
<FieldGroup>
<FieldSet>
<FieldLegend>Payment Method</FieldLegend>
<FieldDescription>
All transactions are secure and encrypted
</FieldDescription>
<FieldGroup>
<Field>
<FieldLabel htmlFor="card-name">Name on Card</FieldLabel>
<Input id="card-name" placeholder="Ada Lovelace" required />
</Field>
<Field>
<FieldLabel htmlFor="card-number">Card Number</FieldLabel>
<Input
id="card-number"
placeholder="1234 5678 9012 3456"
required
/>
<FieldDescription>
Enter your 16-digit card number
</FieldDescription>
</Field>
<FieldGroup className="grid grid-cols-3 gap-4">
<Field>
<FieldLabel htmlFor="exp-month">Month</FieldLabel>
<Select items={monthItems}>
<SelectTrigger id="exp-month" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{months.map((month) => (
<SelectItem key={month} value={month}>
{month}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel htmlFor="exp-year">Year</FieldLabel>
<Select items={yearItems}>
<SelectTrigger id="exp-year" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{years.map((year) => (
<SelectItem key={year} value={year}>
{year}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel htmlFor="cvv">CVV</FieldLabel>
<Input id="cvv" placeholder="123" required />
</Field>
</FieldGroup>
</FieldGroup>
</FieldSet>
<FieldSeparator />
<FieldSet>
<FieldLegend>Billing Address</FieldLegend>
<FieldDescription>
The billing address associated with your payment method
</FieldDescription>
<FieldGroup>
<Field orientation="horizontal">
<Checkbox id="same-as-shipping" defaultChecked />
<FieldLabel htmlFor="same-as-shipping" className="font-normal">
Same as shipping address
</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>
<FieldSet>
<FieldGroup>
<Field>
<FieldLabel htmlFor="comments">Comments</FieldLabel>
<Textarea
id="comments"
placeholder="Add any additional comments"
className="resize-none"
/>
</Field>
</FieldGroup>
</FieldSet>
<Field orientation="horizontal">
<Button type="submit">Submit</Button>
<Button variant="outline" type="button">
Cancel
</Button>
</Field>
</FieldGroup>
</form>
</div>
)
}API Reference
See the Base UI Label documentation for more information.