For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
FrakmentFrakment

Label

An accessible label associated with a form control.

Web
Frakment
label.tsx
"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

Usage

label.tsx
import { Label } from "@/components/ui/label";
tsx
<Label htmlFor="email">Email</Label>
<Input id="email" type="email" />

Examples

Required

Append a * (or any indicator) inline to signal a required field.

label-required.tsx
"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>
  );
}
tsx
<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.

label-disabled.tsx
"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>
  );
}
tsx
<Label htmlFor="dis" className="opacity-50">Disabled field</Label>
<Input id="dis" disabled />

In Context

With input

label-with-input.tsx
"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

label-with-checkbox.tsx
"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.

PropTypeDefaultDescription
htmlForstring—Matches the id of the associated control.
classNamestring—Additional class names.

Accessibility

  • Label renders a native <label>. Always link it to the control via htmlFor matching the id of 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 Label for 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 * plus aria-required on the control.

Anatomy

tsx
<Label htmlFor="field">Field label</Label>
 
<Label htmlFor="required">
  <span className="text-destructive">*</span> Required field
</Label>
  • Text: 14px, medium weight
  • Required marker: a * in destructive color, applied manually