forms
Field
A component that provides labelling and validation for form controls. Built with Base UI and Tailwind CSS. Copy-paste ready.
Installation
Usage
Anatomy
Good to know
Fieldconnects the label, description and error to the control for you. Don't addid,htmlFororaria-describedbyyourself.- It works with the cnippet controls (
Input,Textarea,Select,Checkbox,NumberFieldand others). For a plain element, wrap it inFieldControl. FieldErroronly appears when the field is invalid. Usematchto show a message for one specific problem, e.g.<FieldError match="valueMissing">Required</FieldError>.- Validate with native attributes (
required,type,minLength,pattern) or avalidate={(value) => "message" | null}function. - By default, validation runs when the form is submitted and again on each change after that. Change this with
validationMode("onBlur"or"onChange"). - Give the
Fieldanamewhen it's inside aForm. The name keys its submitted value and any servererrors. - For each option in a checkbox or radio group inside a
Field, useFieldItem.
API Reference
Field
Root container that propagates label/description/error associations to child controls.
FieldLabel
Styled <label> that automatically associates with the field's control.
FieldDescription
Muted helper text linked to the control via aria-describedby.
FieldError
Validation error text. Only visible when the field is invalid.
FieldControl
Invisible proxy that connects arbitrary controls to the field's validation context. Use when the control is not a native input.
FieldValidity
Render-prop component exposing the field's current validity state.
Examples
Required Field
Add the required prop to the control inside Field to display a required indicator on the label and enable browser-native constraint validation.
With Error
Enter an invalid email address and press enter to see the error.
With Validity
Use FieldValidity to render custom UI based on the current validation state — such as a checkmark when the field is valid.
Input Group
Wrap an InputGroup inside Field to get label association and error messaging for complex input compositions.
Autocomplete Field
Use Field with Autocomplete to wire up an accessible label, required validation, and visible error for suggestion inputs.
Combobox Field
Use Field with Combobox for single-selection dropdowns that need accessible labelling and form validation.
Combobox Multi-select
Combines Field with a multi-select Combobox so chip-based selections are validated and described accessibly.
Textarea Field
Wraps a Textarea in Field to provide a label, description, and character-count error for multi-line inputs.
Select Field
Pairs Field with Select for validated dropdown fields with visible labels and inline error messages.
Checkbox Field
A single checkbox wrapped in Field to associate an accessible label with the control and show validation feedback.
Checkbox Group Field
A CheckboxGroup wrapped in Field and Fieldset for group-level labelling, description, and validation.
Radio Group Field
A RadioGroup inside Field and Fieldset to validate that the user has selected one of the available options.
Switch Field
A Switch inside Field for accessible toggle fields that need a visible label and optional error messaging.
Slider Field
Wraps a Slider in Field to provide an accessible label and connect the value to form validation.
Number Field
A NumberField inside Field with a label and error message for validated numeric inputs.
Complete Form
A multi-field form showcasing how Field composes with various input types, all wired up with labels, descriptions, and error messages.
Switch Field
An inline Switch toggle with a label and description, laid out side-by-side using flex-row for compact preference controls.
Date Field
A native date Input wrapped in Field to provide an accessible label, description, and inline error for date-of-birth or deadline inputs.
OTP Field
An OtpField inside Field for verification-code entry, with label, description, and an error message when the code is invalid.
File Upload Field
A type="file" input inside Field with an accept attribute, description of allowed formats, and an error message for invalid uploads.
Password Strength
Uses FieldValidity to render a live strength meter — four coloured bars and a label that update as the user types their new password.