Label

The visible name of a form control.

Source
$npx @dinachi/cli@latest add label
children
disabled

Usage

import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function EmailField() {
  return (
    <div className="grid gap-1.5">
      <Label htmlFor="email">Email</Label>
      <Input id="email" type="email" />
    </div>
  )
}

Examples

A label paired with an input.
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';

export function Example() {
  return (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="email">Email</Label>
      <Input type="email" id="email" placeholder="Email" />
    </div>
  );
}

Notes

Disabled styling

The label dims through Tailwind's peer-disabled:, so it must come after a disabled control with the peer class.

Inside a Field

Inside a Field, use FieldLabel. It wires the label to the control and its validation state.

API

htmlForstring
Id of the named control. Clicking the label focuses it.
children
agent
ReactNode
The name, read by the agent as the control's label.
classNamestring
Merged with the default classes.

Accessibility

  • A native label; its text is the control's accessible name.
  • Link it with htmlFor and a matching id, or wrap the control inside it.
  • The agent addresses a labelled field by its label text.