Label
Renders an accessible label associated with controls.
import { Checkbox } from "~/components/ui/checkbox";import { Label } from "~/components/ui/label";
export default function LabelDemo() { return ( <div class="flex gap-2"> <Checkbox id="terms" /> <Label for="terms">Accept terms and conditions</Label> </div> );}For form fields, use the Field component which includes built-in label, description, and error handling.
Installation
Usage
import { Label } from "~/components/ui/label";<Label for="email">Your email address</Label>Label in Field
For form fields, use the Field component which includes built-in FieldLabel, FieldDescription, and FieldError components.
<Field> <FieldLabel for="email">Your email address</FieldLabel> <Input id="email" /></Field>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, SelectItem, SelectTrigger, SelectValue,} from "~/components/ui/select";import { Textarea } from "~/components/ui/textarea";
const months = [ { label: "01", value: "01" }, { label: "02", value: "02" }, { label: "03", value: "03" }, { label: "04", value: "04" }, { label: "05", value: "05" }, { label: "06", value: "06" }, { label: "07", value: "07" }, { label: "08", value: "08" }, { label: "09", value: "09" }, { label: "10", value: "10" }, { label: "11", value: "11" }, { label: "12", value: "12" },];
const years = [ { label: "2024", value: "2024" }, { label: "2025", value: "2025" }, { label: "2026", value: "2026" }, { label: "2027", value: "2027" }, { label: "2028", value: "2028" }, { label: "2029", value: "2029" },];
export default function FieldDemo() { return ( <div class="w-full max-w-md"> <form> <FieldGroup> <FieldSet> <FieldLegend>Payment Method</FieldLegend> <FieldDescription>All transactions are secure and encrypted</FieldDescription> <FieldGroup> <Field> <FieldLabel for="checkout-card-name">Name on Card</FieldLabel> <Input id="checkout-card-name" placeholder="Evil Rabbit" required /> </Field> <Field> <FieldLabel for="checkout-card-number">Card Number</FieldLabel> <Input id="checkout-card-number" placeholder="1234 5678 9012 3456" required /> <FieldDescription>Enter your 16-digit card number</FieldDescription> </Field> <div class="grid grid-cols-3 gap-4"> <Field> <FieldLabel for="checkout-exp-month">Month</FieldLabel> <Select options={months} optionValue="value" optionTextValue="label" placeholder="MM" itemComponent={(props) => ( <SelectItem item={props.item}>{props.item.rawValue.label}</SelectItem> )} > <SelectTrigger id="checkout-exp-month"> <SelectValue<(typeof months)[number]>> {(state) => state.selectedOption().label} </SelectValue> </SelectTrigger> <SelectContent /> </Select> </Field> <Field> <FieldLabel for="checkout-exp-year">Year</FieldLabel> <Select options={years} optionValue="value" optionTextValue="label" placeholder="YYYY" itemComponent={(props) => ( <SelectItem item={props.item}>{props.item.rawValue.label}</SelectItem> )} > <SelectTrigger id="checkout-exp-year"> <SelectValue<(typeof years)[number]>> {(state) => state.selectedOption().label} </SelectValue> </SelectTrigger> <SelectContent /> </Select> </Field> <Field> <FieldLabel for="checkout-cvv">CVV</FieldLabel> <Input id="checkout-cvv" placeholder="123" required /> </Field> </div> </FieldGroup> </FieldSet> <FieldSeparator /> <FieldSet> <FieldLegend>Billing Address</FieldLegend> <FieldDescription> The billing address associated with your payment method </FieldDescription> <FieldGroup> <Field orientation="horizontal"> <Checkbox id="checkout-same-as-shipping" defaultChecked /> <FieldLabel for="checkout-same-as-shipping" class="font-normal"> Same as shipping address </FieldLabel> </Field> </FieldGroup> </FieldSet> <FieldSet> <FieldGroup> <Field> <FieldLabel for="checkout-comments">Comments</FieldLabel> <Textarea id="checkout-comments" placeholder="Add any additional comments" class="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
Label is a styled native label element. See the HTML label element reference for its native props and accessibility semantics.