Skip to main contentSkip to docs navigation

Chassis

Checkboxes and Radio Buttons

View on GitHub

Style checkboxes, radio buttons, and switches with the form check classes — three sizes, inline and reversed layouts, button toggles, and context colors.

@layer components
MDN Reference
Component tokens

Introduction

The .check-input class replaces the browser's default checkbox and radio rendering with the form colors and icons of Chassis, and the .form-check container sets the gap, the font size, and the alignment of the control and its label. The inputs stay native <input type="checkbox"> and <input type="radio"> elements, so keyboard interaction, form submission, and the accessibility semantics are the browser's own.

Two markup patterns give the same result: sibling markup, an <input> and a <label> connected with id and for inside a .form-check element, and nested markup, where the <label> itself carries .form-check and wraps the <input>.

Basic structure

Add .check-input to an <input type="checkbox"> or <input type="radio"> element and wrap it, with its label, in a .form-check container. The container reserves the space of the input at its inline start and aligns the label text next to it.

Checkboxes

A checkbox is an <input type="checkbox"> with .check-input. The example shows the sibling and the nested markup pattern.

HTML
<!-- Sibling markup pattern -->
<div class="form-check">
  <input class="check-input" type="checkbox" id="checkSibling">
  <label for="checkSibling">Sibling checkbox</label>
</div>

<!-- Nested markup pattern -->
<label class="form-check">
  <input class="check-input" type="checkbox" id="checkNested" checked>
   Nested checkbox
</label>

Radio buttons

A radio button is an <input type="radio"> with .check-input. Radio buttons that share a name form a group in which only one option is selected at a time.

HTML
<label class="form-check">
  <input class="check-input" type="radio" name="radioExample">
  Option one
</label>
<label class="form-check">
  <input class="check-input" type="radio" name="radioExample" checked>
  Option two
</label>

Indeterminate state

The indeterminate state is a third visual state of a checkbox, typically for a parent option whose children are partly selected. HTML has no attribute for it: set the indeterminate property of the input with JavaScript.

HTML
<label class="form-check">
  <input class="check-input" type="checkbox" value="" id="checkIndeterminate">
  Indeterminate checkbox
</label>

Disabled state

Add the disabled attribute to an input to make it unavailable. The input takes the disabled form colors, and a .form-check container that holds a disabled input mutes its label text.

HTML
<label class="form-check">
  <input class="check-input" type="checkbox" value="" id="checkDisabled" disabled>
  Disabled checkbox
</label>
<label class="form-check">
  <input class="check-input" type="checkbox" value="" id="checkCheckedDisabled" checked disabled>
  Disabled checked checkbox
</label><label class="form-check">
  <input class="check-input" type="checkbox" value="" id="checkIndeterminateDisabled" disabled>
  Disabled indeterminate checkbox
</label>
<label class="form-check">
  <input class="check-input" type="radio" value="" id="radioDisabled" disabled>
  Disabled radio
</label>
<label class="form-check">
  <input class="check-input" type="radio" value="" id="radioCheckedDisabled" checked disabled>
  Disabled checked radio
</label>

Switches

A switch is a checkbox with role="switch": the attribute selects the switch styling, a track with a toggle that moves to the inline end when the input is checked. No extra class is needed.

The role also tells assistive technologies that the control turns something on or off; technologies that do not support it announce a regular checkbox. Switches support the disabled attribute.

HTML
<label class="form-check">
  <input class="check-input" type="checkbox" role="switch" id="switchCheckDefault">
  Default switch checkbox input
</label>
<label class="form-check">
  <input class="check-input" type="checkbox" role="switch" id="switchCheckChecked" checked>
  Checked switch checkbox input
</label>
<label class="form-check">
  <input class="check-input" type="checkbox" role="switch" id="switchCheckDisabled" disabled>
  Disabled switch checkbox input
</label>
<label class="form-check">
  <input class="check-input" type="checkbox" role="switch" id="switchCheckCheckedDisabled" checked disabled>
  Disabled checked switch checkbox input
</label>

Descriptive labels

Place a .form-help element inside the .form-check container to describe an option below its label. Add .d-inline to keep the description on the line of the label.

HTML
<label class="form-check">
  <input class="check-input" type="checkbox">
  Checkbox with description
  <small class="form-help">
    This is a helpful description for the checkbox.
  </small>
</label>
<label class="form-check">
  <input class="check-input" type="checkbox">
  Checkbox with inline description
  <small class="form-help fg-subtle d-inline">
    – This is an inline help text for the checkbox.
  </small>
</label>

Without visible labels

Omit the .form-check container for a control without a visible label, such as a checkbox in a table row. The input still needs an accessible name: add aria-label or aria-labelledby (see forms accessibility).

HTML
<input class="check-input" type="checkbox" id="checkboxNoLabel" value="" aria-label="Subscribe to newsletter">
<input class="check-input" type="radio" name="radioNoLabel" id="radioNoLabel1" value="1" aria-label="Select first option">
<input class="check-input" type="radio" name="radioNoLabel" id="radioNoLabel2" value="2" aria-label="Select second option">

Sizing options

Add .sm or .lg to the .form-check container to change the size of the input, the gap, and the font size of the label together.

HTML
<div class="form-check lg">
  <input class="check-input" type="checkbox" id="checkLarge">
  <label for="checkLarge">
    Large checkbox
  </label>
</div>
<div class="form-check">
  <input class="check-input" type="checkbox" id="checkMedium">
  <label for="checkMedium">
    Default checkbox
  </label>
</div>
<div class="form-check sm">
  <input class="check-input" type="checkbox" id="checkSmall">
  <label for="checkSmall">
    Small checkbox
  </label>
</div>

The size classes apply to switches in the same way: .sm or .lg on the .form-check container sets the width and height of the track and the toggle with the label.

HTML
<label class="form-check lg">
  <input class="check-input" type="radio" name="radioSize" id="switchLarge">
    Large switch
</label>
<label class="form-check">
  <input class="check-input" type="radio" name="radioSize" id="switchMedium" checked>
  Default switch
</label>
<label class="form-check sm">
  <input class="check-input" type="radio" name="radioSize" id="switchSmall">
  Small switch
</label>

Sizing without labels

For a control without a .form-check container, add .sm or .lg to the .check-input element itself.

HTML
<input class="check-input lg" type="checkbox">
<input class="check-input" type="checkbox">
<input class="check-input sm" type="checkbox">
  <span class="vr mx-md"></span>
<input class="check-input lg" name="radioSizeInput" type="radio">
<input class="check-input" name="radioSizeInput" type="radio">
<input class="check-input sm" name="radioSizeInput" type="radio">
  <span class="vr mx-md"></span>
<input class="check-input lg" role="switch" name="switchSizeInputLarge" type="checkbox">
<input class="check-input" role="switch" name="switchSizeInputMedium" type="checkbox">
<input class="check-input sm" role="switch" name="switchSizeInputSmall" type="checkbox">

Layout options

.form-check elements are block-level and stack vertically. Flex utilities place them on one line, and the .reverse modifier moves the input to the other side of the label.

Inline layout

Wrap the checks in a flex container, with flex utilities and a gap utility, to display them on one line.

HTML
<div class="d-flex gap-md">
  <label class="form-check">
    <input class="check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
    Option one
  </label>
  <label class="form-check">
    <input class="check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">
    Option two
  </label>
  <label class="form-check">
    <input class="check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" disabled>
    Option three (disabled)
  </label>
</div>

Reversed layout

Add .reverse to the .form-check container to place the input at the inline end of the label and align the text to the end.

HTML
<div class="form-check reverse">
  <input class="check-input" type="checkbox" value="" id="reverseCheck1">
  <label for="reverseCheck1">
    Reverse checkbox
  </label>
</div>
<div class="form-check reverse">
  <input class="check-input" type="checkbox" value="" id="reverseCheck2" disabled>
  <label for="reverseCheck2">
    Disabled reverse checkbox
  </label>
</div>

<div class="form-check reverse">
  <input class="check-input" type="checkbox" role="switch" id="switchCheckReverse">
  <label for="switchCheckReverse">Reverse switch checkbox input</label>
</div>

Button checks

Button checks are checkboxes and radio buttons that look like buttons. Add .button and .button-check to a <label> and nest the input in it: .button-check hides the input visually and keeps it focusable, and the label shows the checked, focused, and disabled states of the input.

Checkbox toggles

A .button-check label with an <input type="checkbox"> toggles on and off independently of the buttons next to it.

HTML
<label class="button button-check default">
  <input type="checkbox" autocomplete="off">
  Button check
</label>
<label class="button button-check default">
  <input type="checkbox" checked autocomplete="off">
  Checked
</label>
<label class="button button-check default">
  <input type="checkbox" autocomplete="off" disabled>
  Disabled
</label>

Screen readers announce a button check as "checkbox, checked" or "checkbox, not checked", since the input keeps its role. A toggle of the button component is announced as "button" or "button, pressed". Use a button check when the control sets a state, and a toggle button when it triggers an action.

Radio toggles

A .button-check label with an <input type="radio"> is one option of a group: inputs that share a name allow one selection at a time.

HTML
<label class="button button-check default">
  <input type="radio" name="options" autocomplete="off" checked>
  Checked
</label>
<label class="button button-check default">
  <input type="radio" name="options" autocomplete="off">
  Radio
</label>
<label class="button button-check default">
  <input type="radio" name="options" autocomplete="off" disabled>
  Disabled
</label>
<label class="button button-check default">
  <input type="radio" name="options" autocomplete="off">
  Radio
</label>

Style variants

Button checks take the context and style classes of the button component, such as .primary, .smooth, and .outline.

HTML
<label class="button button-check default">
  <input type="radio" name="styleOptions" autocomplete="off">
  Default
</label>
<label class="button button-check primary">
  <input type="radio" name="styleOptions" checked autocomplete="off">
  Primary
</label>
<label class="button button-check primary smooth">
  <input type="radio" name="styleOptions" autocomplete="off" checked>
  Primary smooth
</label>
<label class="button button-check secondary outline">
  <input type="radio" name="styleOptions" autocomplete="off">
  Secondary outlined
</label>

Modern inputs

A second markup pattern puts .check-input on a wrapper around the input instead of on the input itself. The wrapper is a context element, so a context class on it colors the checked state, and the check, radio, and indeterminate icons are drawn by the wrapper instead of a background image of the input.

Both patterns are part of the build and work side by side: .check-input on an <input> selects the first one, .check-input on any other element selects this one.

Usage patterns

Wrap the <input> in a .check-input element, a <span> in the examples, and add a context class to the wrapper. The wrapper works inside a .form-check container with nested and with sibling markup.

HTML
<!-- Nested input pattern -->
<label class="form-check">
  <span class="check-input secondary">
    <input type="checkbox" id="checkNestedModern" checked>
  </span>
  Nested input with secondary context color
</label>

<!-- Sibling input pattern -->
<div class="form-check">
  <span class="check-input secondary">
    <input type="checkbox" id="checkSiblingModern" checked>
  </span>
  <label for="checkSiblingModern">Sibling input with secondary context color</label>
</div>

Context variants

Every context class is available on the wrapper. The checked input takes the active background and foreground colors of that context.

HTML
<label class="form-check">
  <span class="check-input default"><input type="checkbox" checked></span>
  Default checkbox
</label>
<label class="form-check">
  <span class="check-input alternate"><input type="checkbox" checked></span>
  Alternate checkbox
</label>
<label class="form-check">
  <span class="check-input primary"><input type="checkbox" checked></span>
  Primary checkbox
</label>
<label class="form-check">
  <span class="check-input secondary"><input type="checkbox" checked></span>
  Secondary checkbox
</label>
<label class="form-check">
  <span class="check-input neutral"><input type="checkbox" checked></span>
  Neutral checkbox
</label>
<label class="form-check">
  <span class="check-input danger"><input type="checkbox" checked></span>
  Danger checkbox
</label>
<label class="form-check">
  <span class="check-input success"><input type="checkbox" checked></span>
  Success checkbox
</label>
<label class="form-check">
  <span class="check-input warning"><input type="checkbox" checked></span>
  Warning checkbox
</label>
<label class="form-check">
  <span class="check-input info"><input type="checkbox" checked></span>
  Info checkbox
</label>
<label class="form-check">
  <span class="check-input black"><input type="checkbox" checked></span>
  Black checkbox
</label>
<label class="form-check">
  <span class="check-input white"><input type="checkbox" checked></span>
  White checkbox
</label>

Disabled inputs

Add the disabled attribute to the <input> inside the wrapper. The wrapper switches to the disabled colors of its context, and a sibling <label> is muted with it.

HTML
<span class="check-input default">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input alternate">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input primary">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input secondary">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input neutral">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input danger">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input success">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input warning">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input info">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input black">
  <input type="checkbox" checked disabled>
</span>
<span class="check-input white">
  <input type="checkbox" checked disabled>
</span>

Radio inputs

The wrapper draws a radio indicator when it holds an <input type="radio">.

HTML
<span class="check-input default">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input alternate">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input primary">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input secondary">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input neutral">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input danger">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input success">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input warning">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input info">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input black">
    <input type="radio" name="radioContext">
  </span>
<span class="check-input white">
    <input type="radio" name="radioContext">
  </span>

Indeterminate checks

The wrapper shows the indeterminate icon when the indeterminate property of its checkbox is set.

HTML
<span class="check-input default">
  <input type="checkbox" id="checkdefaultIndeterminate">
</span>
<span class="check-input alternate">
  <input type="checkbox" id="checkalternateIndeterminate">
</span>
<span class="check-input primary">
  <input type="checkbox" id="checkprimaryIndeterminate">
</span>
<span class="check-input secondary">
  <input type="checkbox" id="checksecondaryIndeterminate">
</span>
<span class="check-input neutral">
  <input type="checkbox" id="checkneutralIndeterminate">
</span>
<span class="check-input danger">
  <input type="checkbox" id="checkdangerIndeterminate">
</span>
<span class="check-input success">
  <input type="checkbox" id="checksuccessIndeterminate">
</span>
<span class="check-input warning">
  <input type="checkbox" id="checkwarningIndeterminate">
</span>
<span class="check-input info">
  <input type="checkbox" id="checkinfoIndeterminate">
</span>
<span class="check-input black">
  <input type="checkbox" id="checkblackIndeterminate">
</span>
<span class="check-input white">
  <input type="checkbox" id="checkwhiteIndeterminate">
</span>

Switch role

A wrapper around an input with role="switch" renders as a switch, and its context class colors the checked track.

HTML
<label class="form-check">
  <span class="check-input default">
    <input type="checkbox" role="switch" checked>
  </span>
  Default switch
</label>
<label class="form-check">
  <span class="check-input alternate">
    <input type="checkbox" role="switch" checked>
  </span>
  Alternate switch
</label>
<label class="form-check">
  <span class="check-input primary">
    <input type="checkbox" role="switch" checked>
  </span>
  Primary switch
</label>
<label class="form-check">
  <span class="check-input secondary">
    <input type="checkbox" role="switch" checked>
  </span>
  Secondary switch
</label>
<label class="form-check">
  <span class="check-input neutral">
    <input type="checkbox" role="switch" checked>
  </span>
  Neutral switch
</label>
<label class="form-check">
  <span class="check-input danger">
    <input type="checkbox" role="switch" checked>
  </span>
  Danger switch
</label>
<label class="form-check">
  <span class="check-input success">
    <input type="checkbox" role="switch" checked>
  </span>
  Success switch
</label>
<label class="form-check">
  <span class="check-input warning">
    <input type="checkbox" role="switch" checked>
  </span>
  Warning switch
</label>
<label class="form-check">
  <span class="check-input info">
    <input type="checkbox" role="switch" checked>
  </span>
  Info switch
</label>
<label class="form-check">
  <span class="check-input black">
    <input type="checkbox" role="switch" checked>
  </span>
  Black switch
</label>
<label class="form-check">
  <span class="check-input white">
    <input type="checkbox" role="switch" checked>
  </span>
  White switch
</label>

Wrapper sizes

Add .sm or .lg to the .form-check container, or to the .check-input wrapper when it stands alone, to change the size of the control.

HTML
<label class="form-check lg">
  <span class="check-input secondary">
    <input type="checkbox" checked>
  </span>
  Large checkbox
</label>
<label class="form-check">
  <span class="check-input secondary">
    <input type="checkbox" checked>
  </span>
  Default checkbox
</label>
<label class="form-check sm">
  <span class="check-input secondary">
    <input type="checkbox" checked>
  </span>
  Small checkbox
</label>
<label class="form-check lg">
  <span class="check-input secondary">
    <input type="checkbox" role="switch" checked>
  </span>
  Large switch
</label>
<label class="form-check">
  <span class="check-input secondary">
    <input type="checkbox" role="switch" checked>
  </span>
  Default switch
</label>
<label class="form-check sm">
  <span class="check-input secondary">
    <input type="checkbox" role="switch" checked>
  </span>
  Small switch
</label>
HTML
<span class="check-input secondary sm">
  <input type="checkbox" name="checkContextSizeSmall">
</span>
<span class="check-input secondary">
  <input type="checkbox" name="checkContextSizeMedium">
</span>
<span class="check-input secondary lg">
  <input type="checkbox" name="checkContextSizeLarge">
</span>
  <span class="vr mx-md"></span>
<span class="check-input secondary sm">
  <input type="radio" name="radioContextSize">
</span>
<span class="check-input secondary">
  <input type="radio" name="radioContextSize">
</span>
<span class="check-input secondary lg">
  <input type="radio" name="radioContextSize">
</span>
  <span class="vr mx-md"></span>
<span class="check-input secondary sm">
  <input type="checkbox" role="switch" name="switchContextSizeSmall">
</span>
<span class="check-input secondary">
  <input type="checkbox" role="switch" name="switchContextSizeMedium">
</span>
<span class="check-input secondary lg">
  <input type="checkbox" role="switch" name="switchContextSizeLarge">
</span>

Accessibility

Checks are native inputs, so their role, their state, and their keyboard interaction come from the browser. The markup around them still has to provide the name of each control and of each group.

Wrap related options in a <fieldset> with a <legend>, so assistive technologies announce the question together with each option:

HTML
<fieldset>
  <legend>Choose your delivery preferences:</legend>
  <div class="form-check">
    <input class="check-input" type="checkbox" id="optEmail">
    <label for="optEmail">Email notifications</label>
  </div>
  <div class="form-check">
    <input class="check-input" type="checkbox" id="optSMS">
    <label for="optSMS">SMS notifications</label>
  </div>
</fieldset>

Focus visibility

A focused input shows the focus ring on :focus-visible. Keep it: keyboard users rely on it to follow their position in a form.

State communication

The checked and the indeterminate state each show an icon in addition to a change of color, so the state does not depend on color alone. A control without a visible label needs aria-label or aria-labelledby for its accessible name.

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

CSS

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

Custom properties

Checks read the custom properties that all form elements share, listed in the forms overview.

Sass variables

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

The size, gap, border, and checked colors of checkboxes and radio buttons:

$form-check-md-size:                    $icon-small;
$form-check-lg-size:                    $icon-medium;
$form-check-sm-size:                    $icon-xsmall;

$form-check-md-gap:                     $space-xsmall;
$form-check-lg-gap:                     $space-small;
$form-check-sm-gap:                     $space-2xsmall;

$form-check-border-width:               $form-regular-border-width;
$form-check-checkbox-border-radius:     $border-radius-small;
$form-check-radio-border-radius:        50%;

$form-check-min-height:                 null;
$form-check-transition:                 null;

$form-check-checked-fg-color:           var(--default-fg-active);
$form-check-checked-bg-color:           var(--default-cue-main);
$form-check-checked-border-color:       $form-check-checked-bg-color;

$form-check-disabled-label-color:       var(--fg-subtle);
$form-check-focus-ring-offset:          $form-input-focus-ring-offset;

The colors and the dimensions of the track and the toggle of switches:

$form-switch-idle-color:                $form-idle-fg-inactive;
$form-switch-disabled-color:            $form-disabled-fg-inactive;
$form-switch-focus-color:               $form-idle-fg-active;
$form-switch-checked-color:             $form-check-checked-fg-color;

$form-switch-md-width:                     2rem;
$form-switch-md-height:                    1.25rem;
$form-switch-md-toggle-width:              1rem;
$form-switch-md-toggle-height:             1rem;

$form-switch-sm-width:                     1.5rem;
$form-switch-sm-height:                    1rem;
$form-switch-sm-toggle-width:              .75rem;
$form-switch-sm-toggle-height:             .75rem;

$form-switch-lg-width:                     2.5rem;
$form-switch-lg-height:                    1.5rem;
$form-switch-lg-toggle-width:              1.25rem;
$form-switch-lg-toggle-height:             1.25rem;


$form-switch-toggle-border-radius:      var(--border-radius-full);
$form-switch-border-radius:             var(--border-radius-full);

$form-switch-icon:                      "<svg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'><circle r='3' fill='currentcolor'/></svg>";
// $form-switch-checked-icon-position:     100%;
$form-switch-transition:                background-position .15s ease-in-out;

Design tokens

The Form check component consumes design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.

The icons of the checked, radio, and indeterminate indicators:

$form-check-checkbox-icon:                $cx-icon-form-input-check-checkbox;
$form-check-indeterminate-icon:           $cx-icon-form-input-check-indeterminate;
$form-check-radio-icon:                   $cx-icon-form-input-check-radio;

The forms overview lists the design tokens that all form elements share.