Skip to main content

Label

Accessible label for form inputs. Built on Radix UI with automatic accessibility features and perfect RTL support.

Preview

Installation

Terminalbash

Usage

Reacttsx

Why Use Label?

Labels are critical for accessibility

  • Screen Readers: Labels are announced by screen readers, telling users what each field is for
  • Click Target: Clicking a label focuses its associated input, improving usability on mobile
  • Form Validation: Browsers use labels to provide better validation messages
  • WCAG Compliance: WCAG 2.1 requires all form inputs to have associated labels

Examples

With Input

tsx

Required Field

tsx

With Helper Text

Must be at least 8 characters long

tsx

Disabled State

Notice how the label automatically becomes muted when the input is disabled

tsx

Horizontal Layout

tsx

Complete Form

tsx

Custom Styling

tsx

Props

NameTypeDefaultDescription
htmlFor
stringundefinedThe ID of the form element this label is associated with
className
stringundefinedAdditional CSS classes to apply

The Label component extends Radix UI's Label primitive and accepts all standard HTML label attributes.

Accessibility

Always Link Labels to Inputs

Use the htmlFor prop with the input's id:

Don't Use Placeholder Instead of Label

❌ Bad: Using only placeholder text (not accessible)

✓ Good: Using label with placeholder

Automatic Disabled Styling

Labels automatically style themselves when their associated input is disabled using the peer-disabled: utility classes.

Keyboard Navigation

Clicking a label focuses its associated input, improving keyboard workflow and mobile usability.

RTL Considerations

Labels automatically support RTL layout. Text alignment adapts based on the text direction.

LTR (English)

RTL (العربية)

Best Practices

Do

  • Always associate labels with form inputs using htmlFor
  • Use clear, concise label text
  • Place labels above or beside inputs consistently
  • Mark required fields visually (e.g., with an asterisk)
  • Ensure labels are visible and not replaced by placeholders

Don't

  • Don't rely solely on placeholder text instead of labels
  • Don't use vague or ambiguous label text
  • Don't hide labels visually without providing alternatives
  • Don't forget to associate labels with their inputs
  • Don't use labels for decorative purposes only

Related Components