Label

A styled, accessible label built on react-aria-components' Label, with medium-weight small text, flex layout, and automatic dimming when its associated control or group is disabled. It is meant to pair with form inputs and other controls.

ui · no preview
This item cannot be built as published, so there is no live preview: build: ✗ Build failed in 379ms
See how it was built

Installation

pnpm dlx shadcn@latest add @kanpeki/label

Requires @kanpeki in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { Label } from "@/components/ui/label";<Label htmlFor="email">Email</Label>
  • Labelling a text field, checkbox, radio, select, or switch so screen readers announce the control's purpose.
  • Captioning a form field with a short, single-line title that should dim automatically when the field is disabled.
  • Adding a clickable label that forwards focus to an associated control through htmlFor or react-aria field context.
  • Building consistent form typography where every field label uses the same size, weight, and spacing.

Examples

Label paired with a native input

Associates the label with an input by id using htmlFor so clicking the label focuses the input.

label-paired-with-a-native-input.tsx
import { Label } from "@/components/ui/label";export function EmailField() {  return (    <div className="flex flex-col gap-1.5">      <Label htmlFor="email">Email</Label>      <input id="email" type="email" className="rounded-md border px-3 py-2 text-sm" />    </div>  );}

Label with an icon and a disabled input

Uses the flex gap to place an inline icon next to the text. The label dims automatically when the peer input is disabled via the peer-disabled variant.

label-with-an-icon-and-a-disabled-input.tsx
import { Label } from "@/components/ui/label";export function ApiKeyField() {  return (    <div className="flex flex-col gap-1.5">      <Label htmlFor="api-key">        <svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">          <path d="M21 2l-2 2m-7.6 7.6a5.5 5.5 0 1 1-7.8 7.8 5.5 5.5 0 0 1 7.8-7.8z" />        </svg>        API key      </Label>      <input id="api-key" disabled className="peer rounded-md border px-3 py-2 text-sm" />    </div>  );}

Label inside a react-aria TextField

Inside a react-aria-components TextField, the Label receives its id and htmlFor automatically from field context, so no manual wiring is needed.

label-inside-a-react-aria-textfield.tsx
import { TextField, Input } from "react-aria-components";import { Label } from "@/components/ui/label";export function NameField() {  return (    <TextField className="flex flex-col gap-1.5">      <Label>Full name</Label>      <Input className="rounded-md border px-3 py-2 text-sm" />    </TextField>  );}

API reference

PropTypeDefaultDescription
classNamestring—Extra class names merged onto the base label styles via the LabelStyles cva helper. Overrides conflicting Tailwind utilities.
data-slotstring"label"Slot identifier set by the component. Can be overridden because the rest props are spread after it.
...restReact.ComponentProps<typeof RACLabel>—All props accepted by react-aria-components' Label (for example htmlFor, id, children, style, and other label element attributes) are forwarded unchanged. The exact set is defined by react-aria-components, not by this wrapper.

Accessibility

  • The underlying element is a native label rendered by react-aria-components, so clicking it moves focus to the associated control.
  • Associate the label with a control by passing htmlFor matching the control's id, or rely on react-aria field context inside TextField, Checkbox, and similar components.
  • Keep label text descriptive and visible. Do not replace it with placeholder text, which disappears on input and is not announced reliably.
  • Disabled state is conveyed visually via opacity. Make sure the associated control also sets disabled so assistive technology receives the state.
  • select-none prevents accidental text selection on click but does not affect screen reader reading of the label text.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Label" component (kanpeki/label) from its shadcn registry.1. Install it with: npx shadcn@latest add @kanpeki/label2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: className, data-slot, ...rest.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Label } from "@/components/ui/label";<Label htmlFor="email">Email</Label>```

Files & dependencies

  • src/registry/ui/label/index.ts
  • src/registry/ui/label/label.tsx
  • src/registry/ui/label/styles.ts
dependenciesreact-aria-components
registryDependencies@kanpeki/cva@kanpeki/custom-plugin

Looks similar, elsewhere

There is no screenshot of this item to compare yet.