Field
Combine labels, controls, and help text to compose accessible form fields and grouped inputs.
Source code
Click to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.
Installation
Usage
<template>
<UiFieldSet>
<UiFieldLegend>Profile</UiFieldLegend>
<UiFieldDescription>This appears on invoices and emails.</UiFieldDescription>
<UiFieldGroup>
<UiField>
<UiFieldLabel for="name">Full name</UiFieldLabel>
<UiInput id="name" autoComplete="off" placeholder="Tinker Bell" />
<UiFieldDescription>This appears on invoices and emails.</UiFieldDescription>
</UiField>
<UiField>
<UiFieldLabel for="username">Username</UiFieldLabel>
<UiInput id="username" autoComplete="off" aria-invalid />
<UiFieldError>Choose another username.</UiFieldError>
</UiField>
<UiField orientation="horizontal">
<UiSwitch id="newsletter" />
<UiFieldLabel for="newsletter">Subscribe to the newsletter</UiFieldLabel>
</UiField>
</UiFieldGroup>
</UiFieldSet>
</template>
Anatomy
The Field family is designed for composing accessible forms. A typical field is structured as follows:
<template>
<UiField>
<UiFieldLabel for="input-id">Label</UiFieldLabel>
<!-- Input, Select, Switch, etc. -->
<UiFieldDescription>Optional helper text.</UiFieldDescription>
<UiFieldError>Validation message.</UiFieldError>
</UiField>
</template>
Fieldis the core wrapper for a single field.FieldContentis a flex column that groups label and description. Not required if you have no description.- Wrap related fields with
FieldGroup, and useFieldSetwithFieldLegendfor semantic grouping.
Examples
Basic
Input
Textarea
Select
Select your department or area of work.
Slider
Set your budget range ($ 200 - 800).
FieldSet
Checkbox
Your Desktop & Documents folders are being synced with iCloud Drive. You can access them from other devices.
Radio
Switch
Enable multi-factor authentication. If you do not have a two-factor device, you can use a one-time code sent to your email.
Notion Prompt
How did you hear about us?
Choice Card
Wrap Field components inside FieldLabel to create selectable field groups. This works with RadioItem, Checkbox and Switch components.
Field Group
Stack Field components with FieldGroup. Add FieldSeparator to divide them.
Responsive Layout
- Vertical fields: Default orientation stacks label, control, and helper text—ideal for mobile-first layouts.
- Horizontal fields: Set
orientation="horizontal"onFieldto align the label and control side-by-side. Pair withFieldContentto keep descriptions aligned. - Responsive fields: Set
orientation="responsive"for automatic column layouts inside container-aware parents. Apply@container/field-groupclasses onFieldGroupto switch orientations at specific breakpoints.
Validation and Errors
- Add
data-invalidtoFieldto switch the entire block into an error state. - Add
aria-invalidon the input itself for assistive technologies. - Render
FieldErrorimmediately after the control or insideFieldContentto keep error messages aligned with the field.
<template>
<UiField data-invalid>
<UiFieldLabel for="email">Email</UiFieldLabel>
<UiInput id="email" type="email" aria-invalid />
<UiFieldError>Enter a valid email address.</UiFieldError>
</UiField>
</template>
Accessibility
FieldSetandFieldLegendkeep related controls grouped for keyboard and assistive tech users.Fieldoutputsrole="group"so nested controls inherit labeling fromFieldLabelandFieldLegendwhen combined.- Apply
FieldSeparatorsparingly to ensure screen readers encounter clear section boundaries.