--- 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 %}
Payment Method

All transactions are secure and encrypted

Enter your 16-digit card number

Billing Address

The billing address associated with your payment method

{% endset %} {{ code_preview("field-demo", code_demo) }}

Usage

Field uses semantic HTML with minimal classes. Two main patterns can be used independently or composed together:

Elements 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">
Field container. Add data-orientation="horizontal" to align controls horizontally. For responsive layouts, use standard Tailwind responsive classes.
<label>
Label for the input.
<input>, <select> or <textarea>
Form input.
<p> Optional
Helper text. Use aria-describedby on the input to reference this element's id.
<p role="alert"> Optional
Error message. Use aria-describedby on the input and aria-invalid="true" to reference this element's id.
<section> Optional
Wraps label and description when the label sits beside the input (e.g. data-orientation="horizontal"). Not required if you have no description.

Fieldsets have the following HTML structure:

<fieldset class="fieldset">
Container for grouping related fields.
<legend>
Heading for the fieldset.
<p> Optional
Description text. When placed directly after <legend>, automatically styled as muted text.
<div role="group" class="field"> Optional
Individual field containers (see structure above). You can include multiple .field elements, or place form controls directly in the fieldset.

Examples

Input

{% set code_input %}

Choose a unique username for your account.

Must be at least 8 characters long.

{% endset %} {{ code_preview("field-input", code_input, class="w-full max-w-md") }}

Textarea

{% set code_textarea %}

Share your thoughts about our service.

{% endset %} {{ code_preview("field-textarea", code_textarea, class="w-full max-w-md") }}

Select

{% set code_select %}

Select your department or area of work.

{% endset %} {{ code_preview("field-select", code_select, class="w-full max-w-md") }}

Slider

{% set code %}

Set your budget: $150

{% endset %} {{ code_preview("slider", code, "w-full max-w-sm") }}

Fieldset

Group related fields with <fieldset class="fieldset"> and <legend>.

{% set code_fieldset %}
Profile

This information will be displayed on your profile

Your first and last name

{% endset %} {{ code_preview("field-fieldset", code_fieldset) }}

Checkbox

{% set code_checkbox %}
Show these items on the desktop

Select the items you want to show on the desktop.


{#
#}

Your Desktop & Documents folders are being synced with iCloud Drive. You can access them from other devices.

{#
#}
{% endset %} {{ code_preview("field-checkbox", code_checkbox, class="w-full max-w-md") }}

Radio Group

{% set code_radio %}
Subscription plan

Yearly and lifetime plans offer significant savings.

{% endset %} {{ code_preview("field-radio", code_radio, class="w-full max-w-md") }}

Switch

Set data-orientation="horizontal" on .field to align labels and controls side-by-side.

{% set code_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.

{% endset %} {{ code_preview("field-switch", code_switch, class="w-full max-w-md") }}

Choice Card

{% set code_choice_card %}
Compute Environment

Select the compute environment for your cluster.

{% endset %} {{ code_preview("field-choice-card", code_choice_card, class="w-full max-w-md") }}

Responsive Layout

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.

{% set code_responsive %}
Profile

Keep your profile details up to date.


Provide your full name for identification.


You can write your message here. Keep it short, preferably under 100 characters.


{% endset %} {{ code_preview("field-responsive", code_responsive, class="w-full max-w-3xl") }}