Skip to main contentSkip to docs navigation

Chassis

A universal layout wrapper for form controls that handles label, description, and validation feedback placement with CSS grid.

@layer components
Component tokens

Introduction

The .form-field wrapper lays out a form control with its label, its description, and its validation feedback, and sets the gap between them. It holds a single input, a stack of inputs, or a group of checkboxes, radio buttons, or switches.

We’ll never share your email with anyone else.
HTML
<div class="form-field">
  <label class="form-label" for="fieldOverview">Email address</label>
  <input class="form-input" type="email" id="fieldOverview" placeholder="name@example.com" aria-describedby="fieldOverviewHelp">
  <div class="form-help" id="fieldOverviewHelp">
    We’ll never share your email with anyone else.
  </div>
</div>

How it works

The .form-field wrapper uses CSS grid to manage the layout of a form control alongside its label, description, and validation feedback.

  • Default layout — a single-column grid in which everything stacks vertically. Use it for text inputs, selects, textareas, ranges, input groups, and adorned inputs.
  • Two-column layout — applies through :has() when a .check-input is a direct child. The control sits in column 1, and its label in column 2.
  • Margin reset — a direct-child .form-label, .form-help, or feedback element loses its own margin, so the grid gap is the only space between the parts.
  • Spanning elements — a .form-label or .form-help next to a direct-child .check-input spans both columns.
  • Grouped controls — several .form-input or .form-check elements inside one .form-field share its label, description, and validation feedback.

Always associate labels with their corresponding input using the for attribute to ensure accessibility.

Basic structure

Wrap a form control, its .form-label, and an optional .form-help in a .form-field element. The same wrapper takes stacked inputs and groups of checks.

Input stacking

A field holds any number of stacked inputs under one label. The description and the validation feedback are optional.

Select "Other" to enter a custom option.
HTML
<div class="form-field">
  <label for="stackedSelect" class="form-label">Options</label>
  <select class="form-input" id="stackedSelect" aria-describedby="stackedHelp">
    <option>Choose an option</option>
    <option value="1">Option one</option>
    <option value="2">Option two</option>
    <option value="other" selected>Other</option>
  </select>
  <input class="form-input" type="text" aria-label="Custom option" placeholder="Please enter">
  <div class="form-help" id="stackedHelp">
    Select "Other" to enter a custom option.
  </div>
</div>

Checkbox

With a .check-input as a direct child, the grid switches to the two-column layout: the checkbox in column 1 and its label in column 2.

Choose options
You can select multiple options.
HTML
<fieldset class="form-field">
  <legend class="form-label">Choose options</legend>
  <input class="check-input" type="checkbox" id="fieldCheck1" aria-describedby="checkGroupHelp" />
  <label for="fieldCheck1">Option one</label>
  <input class="check-input" type="checkbox" id="fieldCheck2" aria-describedby="checkGroupHelp" />
  <label for="fieldCheck2">Option two</label>
  <div class="form-help" id="checkGroupHelp">You can select multiple options.</div>
</fieldset>

Add role="switch" to each checkbox to render it as a switch, with the switch at the inline start and the label after it.

Choose options
HTML
<fieldset class="form-field">
  <legend class="form-label">Choose options</legend>
  <input class="check-input" type="checkbox" role="switch" id="fieldSwitch1" />
  <label for="fieldSwitch1">Option one</label>
  <input class="check-input" type="checkbox" role="switch" id="fieldSwitch2" />
  <label for="fieldSwitch2">Option two</label>
</fieldset>

Without fieldset

Where a <fieldset> does not fit, for example inside a grid or flex layout that conflicts with its block formatting, add role="group" and aria-labelledby to the .form-field wrapper instead.

Choose options
You can select multiple options.
HTML
<div class="form-field" role="group" aria-labelledby="noFsGroupLabel">
  <div class="form-label" id="noFsGroupLabel">Choose options</div>
  <input class="check-input" type="checkbox" id="noFsCheck1" aria-describedby="noFsCheckHelp" />
  <label for="noFsCheck1">Option one</label>
  <input class="check-input" type="checkbox" id="noFsCheck2" aria-describedby="noFsCheckHelp" />
  <label for="noFsCheck2">Option two</label>
  <div class="form-help" id="noFsCheckHelp">You can select multiple options.</div>
</div>

Descriptions

Wrap each checkbox, radio button, or switch in a .form-check element to give it a description of its own: a .form-help inside the check aligns with its label, and a .form-help of the field describes the whole group.

Select a plan
$9/month — For individuals.
$29/month — For teams.
Prices are in USD and exclude applicable taxes.
HTML
<fieldset class="form-field">
  <legend class="form-label">Select a plan</legend>
  <div class="form-check">
    <input type="radio" id="fieldDescription1" class="check-input" name="fieldDescription" checked aria-describedby="fieldDescription1Help" />
    <label for="fieldDescription1">Basic</label>
    <div class="form-help font-sm" id="fieldDescription1Help">$9/month — For individuals.</div>
  </div>
  <div class="form-check">
    <input type="radio" id="fieldDescription2" class="check-input" name="fieldDescription" aria-describedby="fieldDescription2Help" />
    <label for="fieldDescription2">Pro</label>
    <div class="form-help font-sm" id="fieldDescription2Help">$29/month — For teams.</div>
  </div>
  <div class="form-help">
    Prices are in USD and exclude applicable taxes.
  </div>
</fieldset>

Form cards

Add .form-card to each .form-check of a field to present the options as cards. A card shows a highlight background and a border while its input is checked, and the whole card is clickable.

Select a plan
$9/month — For individuals.
$29/month — For teams.
HTML
<fieldset class="form-field">
  <legend class="form-label">Select a plan</legend>
    <div class="form-check form-card">
      <input type="radio" id="fieldCard1" class="check-input" name="fieldCard" checked aria-describedby="fieldCard1Help" />
      <label for="fieldCard1">Basic</label>
      <div class="form-help font-sm" id="fieldCard1Help">$9/month — For individuals.</div>
    </div>
    <div class="form-check form-card">
      <input type="radio" id="fieldCard2" class="check-input" name="fieldCard" aria-describedby="fieldCard2Help" />
      <label for="fieldCard2">Pro</label>
      <div class="form-help font-sm" id="fieldCard2Help">$29/month — For teams.</div>
  </div>
</fieldset>

Label as card

With nested markup, the <label> itself carries .form-check and .form-card and wraps the input, its text, and its description.

Select a plan
HTML
<fieldset class="form-field">
  <legend class="form-label">Select a plan</legend>
    <label class="form-check form-card">
      <input type="radio" id="labelCard1" class="check-input" name="labelCard" checked />
      Basic
      <small class="form-help d-block">$9/month — For individuals.</small>
    </label>
    <label class="form-check form-card">
      <input type="radio" id="labelCard2" class="check-input" name="labelCard" />
      Pro
      <small class="form-help d-block">$29/month — For teams.</small>
  </label>
</fieldset>

Input groups

An input group inside a .form-field joins related inputs under one label and one description. Add role="group" and aria-labelledby to the .form-field wrapper so assistive technologies announce the group name alongside each input.

Enter your first and last name.
HTML
<div class="form-field" role="group" aria-labelledby="nameGroupLabel">
  <label class="form-label" for="groupedFirstName" id="nameGroupLabel">Name</label>
  <div class="input-group">
    <input type="text" class="form-input" id="groupedFirstName" placeholder="First" aria-label="First name" aria-describedby="groupedNameHelp">
    <input type="text" class="form-input" placeholder="Last" aria-label="Last name" aria-describedby="groupedNameHelp">
  </div>
  <div class="form-help" id="groupedNameHelp">
    Enter your first and last name.
  </div>
</div>

Accessibility

A field is layout only: the association of a control with its label, its group, and its description is written in the markup.

Label association

Always use a <label> element with a for attribute matching the id of its input. This is the most reliable way to associate a label with a control and is required for screen readers and other assistive technologies.

HTML
<div class="form-field">
  <label class="form-label" for="emailField">Email address</label>
  <input class="form-input" type="email" id="emailField" />
</div>

Grouped controls

When grouping related checkboxes or radio buttons, use a <fieldset> with a <legend> so that screen readers announce the group's purpose alongside each option.

HTML
<fieldset class="form-field">
  <legend class="form-label">Select a plan</legend>
  <div class="form-check">
    <input type="radio" id="plan1" class="check-input" name="plan" />
    <label for="plan1">Basic</label>
  </div>
  <div class="form-check">
    <input type="radio" id="plan2" class="check-input" name="plan" />
    <label for="plan2">Pro</label>
  </div>
</fieldset>

Where a <fieldset> does not fit, add role="group" and aria-labelledby to the .form-field wrapper instead:

HTML
<div class="form-field" role="group" aria-labelledby="planGroupLabel">
  <div class="form-label" id="planGroupLabel">Select a plan</div>
  <div class="form-check">
    <input type="radio" id="plan3" class="check-input" name="planAlt" />
    <label for="plan3">Basic</label>
  </div>
  <div class="form-check">
    <input type="radio" id="plan4" class="check-input" name="planAlt" />
    <label for="plan4">Pro</label>
  </div>
</div>

Help and feedback

Use aria-describedby to associate .form-help text and validation feedback with their input, so screen readers announce the description when the field receives focus.

HTML
<div class="form-field">
  <label class="form-label" for="emailField">Email address</label>
  <input class="form-input" type="email" id="emailField" aria-describedby="emailHelp" />
  <div class="form-help" id="emailHelp">We'll never share your email with anyone else.</div>
</div>

When displaying a validation error, also set aria-invalid="true" on the input and point aria-describedby at the error message:

HTML
<div class="form-field">
  <label class="form-label" for="emailField">Email address</label>
  <input class="form-input is-invalid" type="email" id="emailField"
         aria-describedby="emailError" aria-invalid="true" />
  <div class="invalid-feedback" id="emailError">Please enter a valid email address.</div>
</div>

Switches

A switch is a checkbox with role="switch", which conveys its on/off nature to assistive technologies. Always pair a switch with a visible <label>.

See forms accessibility for the guidance that applies to all form controls.

CSS

The Form Field component can be customized through Sass variables at compile time.

Custom properties

The Form Field component exposes CSS custom properties to control its appearance at runtime.

The gap between the parts of a field:

--gap: var(--form-field-gap, #{$form-field-gap});

The padding of a form card:

--padding-x: var(--form-card-padding-x, #{$form-card-padding-x});
--padding-y: var(--form-card-padding-y, #{$form-card-padding-y});

Sass variables

The Form Field component uses Sass variables in scss/config/_defaults.scss to define its defaults.

$form-field-gap:                        $space-xsmall;
$form-card-padding-x:                   $space-small;
$form-card-padding-y:                   $space-small;

The variables of .form-label and .form-help:

$form-label-font:                       $form-md-label-font;
$form-label-color:                      var(--fg-main);
$form-label-margin-bottom:              $form-field-gap;
$form-help-font:                        $font-ui-medium-normal;
$form-help-input-spacing:               $form-field-gap;
$form-help-check-spacing:               $space-zero;
$form-help-range-spacing:               $space-zero;