Label

Renders an accessible caption for a form control.

import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function LabelDemo() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="label-demo-email">Email</Label>
      <Input id="label-demo-email" type="email" placeholder="me@example.com" />
    </VStack>
  )
}

Installation

pnpm dlx shadcn@latest add @arene/label

Needs the arene setup first.

Usage

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

Disabled

Use the disabled prop to dim the label and take it out of the hit test. It is a prop rather than an inherited state. Inside a Field the FieldLabel reads it from the field; a bare label has nothing to read it from.

import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function LabelDisabled() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="label-disabled-plan" disabled>
        Billing plan
      </Label>
      <Input id="label-disabled-plan" defaultValue="Enterprise" disabled />
    </VStack>
  )
}

Content

The label is a flex row with a 0.5rem gap, so an icon or a Badge sits beside the text without extra markup.

import { Badge } from "@/components/ui/badge"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { LockSimpleIcon } from "@phosphor-icons/react/dist/csr/LockSimple"
import { widths } from "@/theme/widths"

export default function LabelContent() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="label-content-secret">
        <LockSimpleIcon aria-hidden="true" />
        Signing secret
        <Badge variant="secondary">Recommended</Badge>
      </Label>
      <Input id="label-content-secret" type="password" placeholder="whsec_..." />
    </VStack>
  )
}

Give the label either an htmlFor matching the control's id or the control itself as a child. Without one of the two the label is decoration, and clicking it does not focus anything.

API reference

Pass render to replace a part's element or compose it with another component.

Label renders a <label> and accepts every <label> attribute.

Label

PropTypeDefault
disabledbooleanfalse
htmlForstring—
xstyleStyleXStyles—
classNamestring—

The line height is 1 rather than the sm leading the type scale pairs with text.sm. A label is one line. With the tight box, the stack's gap alone sets the distance to the control below.

labelStyles

The style maps behind the component. Spread them onto any element.

KeyWhat it is
baseThe row: gap, type, weight, icon size
disabledThe dimmed, non-interactive state

disabled is states.disabled from theme/states.ts, the same dimmed style every control uses.

Data attributes

AttributeOnEffect
data-slot="label"the labelTargets the label from a parent
data-disabledthe labelPresent when disabled is set