Get Started
Components
- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
AI Elements
Libraries
Utilities
"use client";
import type * as React from "react";
import { cn } from "@/lib/utils";
function Label({
className,
onMouseDown,
...props
}: React.ComponentProps<"label">) {
return (
<label
className={cn(
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)}
data-slot="label"
onMouseDown={(event) => {
onMouseDown?.(event);
if (!event.defaultPrevented && event.detail > 1) {
event.preventDefault();
}
}}
{...props}
/>
);
}
export { Label };Label renders a native <label> that forwards clicks to its associated control via htmlFor. Disabled styling is inherited automatically when the wrapped control is disabled.
Installation
$ bunx --bun frakment add label$ npx frakment add label$ pnpm dlx frakment add label$ yarn dlx frakment add label
Copy and paste the following code into your project.
"use client";
import type * as React from "react";
import { cn } from "@/lib/utils";
function Label({
className,
onMouseDown,
...props
}: React.ComponentProps<"label">) {
return (
<label
className={cn(
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)}
data-slot="label"
onMouseDown={(event) => {
onMouseDown?.(event);
if (!event.defaultPrevented && event.detail > 1) {
event.preventDefault();
}
}}
{...props}
/>
);
}
export { Label };Update the import paths to match your project setup.
Usage
import { Label } from "@/components/ui/label";<Label htmlFor="email">Email</Label>
<Input id="email" type="email" />Examples
Required
Append a * (or any indicator) inline to signal a required field.
"use client";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export function LabelRequired() {
return (
<div className="flex w-full max-w-sm flex-col gap-2">
<Label htmlFor="req">
Email <span className="text-destructive">*</span>
</Label>
<Input id="req" placeholder="required" required type="email" />
</div>
);
}<Label htmlFor="req">
Email <span className="text-destructive">*</span>
</Label>Disabled
When the associated control is disabled, dim the label with opacity-50 to match the control.
"use client";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export function LabelDisabled() {
return (
<div className="flex w-full max-w-sm flex-col gap-2">
<Label className="opacity-50" htmlFor="dis">
Disabled field
</Label>
<Input defaultValue="Cannot edit" disabled id="dis" />
</div>
);
}<Label htmlFor="dis" className="opacity-50">Disabled field</Label>
<Input id="dis" disabled />In Context
With input
"use client";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export function LabelWithInput() {
return (
<div className="mx-auto flex w-full max-w-sm flex-col gap-2">
<Label htmlFor="name">Name</Label>
<Input id="name" placeholder="Your name" />
</div>
);
}With checkbox
"use client";
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
export function LabelWithCheckbox() {
return (
<div className="mx-auto flex items-center gap-2">
<Checkbox id="terms" />
<Label htmlFor="terms">Accept terms</Label>
</div>
);
}API Reference
Label
Renders a native <label> element. Accepts all native label attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
htmlFor | string | — | Matches the id of the associated control. |
className | string | — | Additional class names. |
Accessibility
Labelrenders a native<label>. Always link it to the control viahtmlFormatching theidof the control.- Clicking the label focuses or toggles the associated control. This is the primary benefit for touch users.
- Do not nest interactive content inside
Label. A link or button inside a label breaks its click behavior. - When marking a field required, add
aria-required="true"on the control, not the label alone.
Best Practices
- Always link via
htmlFor. An unlinked label is decorative; screen readers ignore it. - Keep labels short. One to three words; put detail in
FieldDescription. - Use
Labelfor every form control.Input,Textarea,Select,Checkbox,Switch. - Avoid labels inside tooltips. They disappear when the user moves away.
- Mark required fields explicitly. Use a
*plusaria-requiredon the control.
Anatomy
<Label htmlFor="field">Field label</Label>
<Label htmlFor="required">
<span className="text-destructive">*</span> Required field
</Label>- Text: 14px, medium weight
- Required marker: a
*indestructivecolor, applied manually