Pittaya UI
Pittaya UI
Links

Search Components

Search for components by name, description, category or tags

Formsstable

Label

An accessible label component that renders a caption associated with a control, built on Radix UI Label primitive.

Newsletter
Subscribe to our newsletter to get the latest updates.

Installation

Install the component directly into your project using the Pittaya CLI.

npx pittaya@latest add label

When to use

Use the Label component to provide accessible, descriptive text for form controls. Labels are essential for accessibility, helping users understand what information is expected in form fields.

The component is built on Radix UI's Label primitive, ensuring proper semantic HTML and accessibility features like automatic focus behavior when clicking the label.

Best practices

  • Always associate labels with their corresponding form controls using the htmlFor attribute matching the input's id.
  • Keep label text concise and descriptive, clearly indicating what input is expected.
  • Place labels above or to the left of form fields for optimal readability and accessibility.
  • Use the Label component even for custom form controls to maintain accessibility standards.
  • Combine with helper text or error messages below the input for additional context.
  • Avoid using placeholder text as a replacement for labels, as it disappears when users start typing.

Accessibility

The Label component is built with accessibility as a priority, leveraging Radix UI's Label primitive for optimal support.

  • Automatically focuses associated form controls when the label is clicked, improving usability.
  • Properly implements for attribute to create semantic relationships with form controls.
  • Supports peer-disabled styling to visually indicate when the associated control is disabled.
  • Works seamlessly with screen readers, announcing the label text when users navigate to the associated control.
  • Includes select-none to prevent accidental text selection, improving the user experience.

Examples

Combine variants and sizes to meet your needs.

Basic usage

A simple label associated with an input field using the htmlFor attribute.

Newsletter
Subscribe to our newsletter to get the latest updates.

With helper text

Label combined with helper text to provide additional context to users.

Create Username
Choose a unique handle for your profile.
Must be 3-20 characters long.

Required field

Label with a visual indicator for required fields using an asterisk.

Login
Enter your password to access your account.

Disabled state

Label automatically adjusts opacity when the associated control is disabled.

Account Settings
Some fields cannot be modified directly.

This ID is unique to your account and cannot be changed.

Form group

Multiple labels and inputs organized in a complete form layout.

Create Account

Enter your details to get started.

With icon

Label with an icon for enhanced visual communication and better user experience.

Contact Support
We usually respond within 24 hours.

Properties

TSX interface that combines variants and default attributes.

PropTypeDefaultDescription
htmlFor
stringThe id of the form control this label is associated with. Creates an accessible relationship between label and control.
className
stringAdditional CSS classes to customize the label appearance.
children
React.ReactNodeThe label text or content to display.