# Label

An accessible label associated with a form control.

> For the complete documentation index, see [llms.txt](/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](/.well-known/agent-skills/site-skill.md).

<DocsBaseSwitcher base="web" component="label" />

<ComponentPreview name="label" title="label.tsx">
<LabelDemo />
</ComponentPreview>

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 [#installation]

<CodeTabs>
<TabsList>
<TabsTrigger value="cli">
Command
</TabsTrigger>

<TabsTrigger value="manual">
Manual
</TabsTrigger>
</TabsList>

<TabsContent value="cli">
```bash
npx frakment add label
```
</TabsContent>

<TabsContent value="manual">
<Steps>
<Step>
Copy and paste the following code into your project.
</Step>

<ComponentSource name="label" title="components/ui/label.tsx" />

<Step>
Update the import paths to match your project setup.
</Step>
</Steps>
</TabsContent>
</CodeTabs>

## Usage [#usage]

```tsx title="label.tsx"
import { Label } from "@/components/ui/label";
```

```tsx
<Label htmlFor="email">Email</Label>
<Input id="email" type="email" />
```

## Examples [#examples]

### Required [#required]

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

<ComponentPreview name="label-required" title="label-required.tsx" src="examples/label-required.tsx">
<LabelRequired />
</ComponentPreview>

```tsx
<Label htmlFor="req">
  Email <span className="text-destructive">*</span>
</Label>
```

### Disabled [#disabled]

When the associated control is disabled, dim the label with `opacity-50` to match the control.

<ComponentPreview name="label-disabled" title="label-disabled.tsx" src="examples/label-disabled.tsx">
<LabelDisabled />
</ComponentPreview>

```tsx
<Label htmlFor="dis" className="opacity-50">Disabled field</Label>
<Input id="dis" disabled />
```

## In Context [#in-context]

### With input [#with-input]

<ComponentPreview name="label-with-input" title="label-with-input.tsx" src="examples/label-with-input.tsx">
<LabelWithInput />
</ComponentPreview>

### With checkbox [#with-checkbox]

<ComponentPreview name="label-with-checkbox" title="label-with-checkbox.tsx" src="examples/label-with-checkbox.tsx">
<LabelWithCheckbox />
</ComponentPreview>

## API Reference [#api-reference]

### Label [#label]

Renders a native `<label>` element. Accepts all native label attributes.

<PropsTable rows={[{"name":"htmlFor","type":"string","description":"Matches the id of the associated control."},{"name":"className","type":"string","description":"Additional class names."}]} />

## Accessibility [#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 [#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 [#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