--- layout: layouts/page.njk title: Field description: Combine labels, controls, and help text to compose accessible form fields. toc: - label: Usage id: usage - label: Examples id: examples children: - label: Input id: example-input - label: Textarea id: example-textarea - label: Select id: example-select - label: Fieldset id: example-fieldset - label: Checkbox id: example-checkbox - label: Radio Group id: example-radio - label: Switch id: example-switch - label: Responsive Layout id: example-responsive --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% set code_demo %}
{% endset %} {{ code_preview("field-demo", code_demo) }}Field uses semantic HTML with minimal classes. Two main patterns can be used independently or composed together:
<div role="group" class="field"> for individual field containers (label, input, helper text, errors)<fieldset class="fieldset"> for grouping multiple related fields togetherElements inside these containers are styled automatically based on their purpose. Use aria-describedby to connect helper text and errors to inputs for accessibility.
Fields have the following HTML structure:
<div role="group" class="field">data-orientation="horizontal" to align controls horizontally. For responsive layouts, use standard Tailwind responsive classes.
<label><input>, <select> or <textarea><p> Optionalaria-describedby on the input to reference this element's id.<p role="alert"> Optionalaria-describedby on the input and aria-invalid="true" to reference this element's id.<section> Optionaldata-orientation="horizontal"). Not required if you have no description.Fieldsets have the following HTML structure:
<fieldset class="fieldset"><legend><p> Optional<legend>, automatically styled as muted text.<div role="group" class="field"> Optional.field elements, or place form controls directly in the fieldset.Choose a unique username for your account.
Must be at least 8 characters long.
Share your thoughts about our service.
Select your department or area of work.
Set your budget: $150
Group related fields with <fieldset class="fieldset"> and <legend>.
Set data-orientation="horizontal" on .field to align labels and controls side-by-side.
Enable multi-factor authentication. If you do not have a two-factor device, you can use a one-time code sent to your email.
For responsive layouts, use standard Tailwind responsive classes directly on .field. This example stacks vertically on mobile and switches to horizontal at the md breakpoint.