Label

Forms
Core

Accessible form labels with automatic focus handling, built on Radix UI primitives. Provides proper association between labels and form controls.

Preview

Basic label with text input

With Different Inputs

Label works with any form control

Required Indicator

Show required field indicator

Variants

Different semantic styles

This field has an error

Sizes

Different text sizes

Disabled State

Label styling for disabled inputs

Props

Label component API reference

PropTypeDefaultDescription
htmlForstringID of the input element to associate with
variant'default' | 'muted' | 'error''default'Visual variant
size'sm' | 'md' | 'lg''md'Text size
requiredbooleanfalseShow required asterisk
children*ReactNodeLabel text content
classNamestringAdditional CSS classes

Usage

Import and implementation example

import { Label } from '@/components/ui/label'
import { Input } from '@/components/ui/input'
import { Checkbox } from '@/components/ui/checkbox'

export default function Example() {
  return (
    <>
      {/* Basic label with input */}
      <div className="space-y-2">
        <Label htmlFor="email">Email</Label>
        <Input id="email" type="email" />
      </div>

      {/* Required field indicator */}
      <div className="space-y-2">
        <Label htmlFor="name" required>Name</Label>
        <Input id="name" />
      </div>

      {/* With checkbox */}
      <div className="flex items-center space-x-2">
        <Checkbox id="terms" />
        <Label htmlFor="terms">Accept terms</Label>
      </div>

      {/* Different variants */}
      <Label variant="default">Default</Label>
      <Label variant="muted">Muted</Label>
      <Label variant="error">Error</Label>

      {/* Different sizes */}
      <Label size="sm">Small</Label>
      <Label size="md">Medium</Label>
      <Label size="lg">Large</Label>
    </>
  )
}

Features

Built-in functionality

  • Radix UI primitives: Built on accessible unstyled components
  • Automatic association: Links to input via htmlFor attribute
  • Click activation: Clicking label focuses associated input
  • Three variants: Default, muted, and error styles
  • Three sizes: Small, medium, and large text
  • Required indicator: Automatic red asterisk for required fields
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

Uses native label semantics via RadixAutomatically linked via htmlForSupports aria-labelledby pattern

Keyboard Navigation

KeyAction
ClickFocus the associated input

Notes

  • Always use with form controls for accessibility
  • htmlFor must match the input id
  • Provides accessible name for screen readers
  • Required indicators use visual asterisk