Field
Composable components for building accessible form layouts with labels, controls, descriptions, and error messages.
Examples
Basic Text Input
<c-field style="max-width: 400px;">
<c-label data-slot="field-label" for="field-email">Email</c-label>
<c-input
id="field-email"
type="email"
placeholder="you@example.com"
></c-input>
<c-field-description>We'll never share your email.</c-field-description>
</c-field>
With Validation Error
<c-field invalid style="max-width: 400px;">
<c-label data-slot="field-label" for="field-username">Username</c-label>
<c-input
id="field-username"
type="text"
value="admin"
aria-invalid="true"
></c-input>
<c-field-error>Username is already taken.</c-field-error>
</c-field>
Textarea Field
<c-field style="max-width: 400px;">
<c-label data-slot="field-label" for="field-bio">Bio</c-label>
<c-textarea
id="field-bio"
rows="4"
placeholder="Tell us about yourself..."
></c-textarea>
<c-field-description
>Brief description for your profile. Max 250
characters.</c-field-description
>
</c-field>
Horizontal Orientation
<c-field orientation="horizontal" style="max-width: 500px;">
<c-label data-slot="field-label" for="field-company" style="width: 120px;"
>Company</c-label
>
<c-input id="field-company" type="text" placeholder="Acme Inc."></c-input>
</c-field>
Field Group with Separator
<c-field-group class="w-full block" style="max-width: 400px;">
<c-field>
<c-label data-slot="field-label" for="field-first-name">First Name</c-label>
<c-input id="field-first-name" type="text" placeholder="John"></c-input>
</c-field>
<c-field>
<c-label data-slot="field-label" for="field-last-name">Last Name</c-label>
<c-input id="field-last-name" type="text" placeholder="Doe"></c-input>
</c-field>
<c-field-separator></c-field-separator>
<c-field>
<c-label data-slot="field-label" for="field-email-secondary">Email</c-label>
<c-input
id="field-email-secondary"
type="email"
placeholder="john@example.com"
></c-input>
</c-field>
</c-field-group>
Checkbox Group with Fieldset
<c-field-set class="w-full block" style="max-width: 400px;">
<c-field-legend>Notifications</c-field-legend>
<c-field-description
>Choose which notifications you want to receive.</c-field-description
>
<div class="flex flex-col gap-3 mt-4">
<div class="flex items-center gap-2">
<c-checkbox id="notifications-email" checked></c-checkbox>
<c-label label-for="notifications-email">Email notifications</c-label>
</div>
<div class="flex items-center gap-2">
<c-checkbox id="notifications-sms"></c-checkbox>
<c-label label-for="notifications-sms">SMS notifications</c-label>
</div>
<div class="flex items-center gap-2">
<c-checkbox id="notifications-push" checked></c-checkbox>
<c-label label-for="notifications-push">Push notifications</c-label>
</div>
</div>
</c-field-set>
Radio Group with Fieldset
<c-field-set class="w-full block" style="max-width: 400px;">
<c-field-legend>Plan</c-field-legend>
<c-field-description>Select your subscription plan.</c-field-description>
<c-radio-group value="free" radio-group-classes="flex flex-col gap-3 mt-4">
<div class="flex items-center gap-2">
<c-radio-group-item id="plan-free" value="free"></c-radio-group-item>
<c-label label-for="plan-free">Free - $0/month</c-label>
</div>
<div class="flex items-center gap-2">
<c-radio-group-item id="plan-pro" value="pro"></c-radio-group-item>
<c-label label-for="plan-pro">Pro - $10/month</c-label>
</div>
<div class="flex items-center gap-2">
<c-radio-group-item
id="plan-enterprise"
value="enterprise"
></c-radio-group-item>
<c-label label-for="plan-enterprise">Enterprise - $50/month</c-label>
</div>
</c-radio-group>
</c-field-set>
Responsive Layout
<c-field-group class="w-full block" style="max-width: 600px;">
<c-field orientation="responsive">
<c-label
data-slot="field-label"
for="field-full-name"
style="min-width: 120px;"
>Full Name</c-label
>
<c-input id="field-full-name" type="text" placeholder="John Doe"></c-input>
</c-field>
</c-field-group>
API Reference
Field
Main wrapper component for form fields with orientation and validation support.
FieldLabel
Label element for form fields with accessibility support.
FieldDescription
Helper text element for providing additional context.
FieldError
Error message element for validation feedback.
FieldContent
Flex column wrapper for grouping label and description.
FieldGroup
Container for grouping multiple fields with container query support.
FieldSeparator
Visual divider for separating field groups.
FieldSet
Semantic fieldset wrapper for grouping related form controls.
FieldLegend
Legend element for fieldset titles.
Accessibility
- Field uses
role="group"for semantic grouping - FieldLabel creates proper label associations
- FieldSet/FieldLegend provide semantic grouping for related controls
- Error messages are linked to form controls for screen readers
- All components support keyboard navigation
Usage Notes
- Use FieldSet/FieldLegend for semantic grouping (checkbox/radio groups)
- Use FieldGroup for layout grouping of multiple fields
- Coordinate
invalidprop on Field witharia-invalidon input elements - Use FieldContent to group label and description together
- Container query (
@container/field-group) enables responsive layouts