Skip to content
Fleetline

Checkbox

Usage

Use checkboxes when people can pick any number of options (including none) — inspection items, vehicle features, which depots to include in a report — or to confirm a single statement. Use radios when only one answer is allowed, and a switch for a setting that applies immediately.

Anatomy

  1. Box — input[type=checkbox].checkbox__input (native, appearance: none), 24px
  2. Check / dash mark — masked ::before
  3. Label — label.checkbox__label[for], part of the hit area
  4. Hint (optional) — .checkbox__hint, wired with aria-describedby
  5. Group — fieldset.checkbox-group with legend, hint, error and .checkbox-group__items

Examples

Hover and focus-visible are frozen with .is-hover and .is-focus-visible, which share their rules with the real pseudo-classes.

Checkbox

Available after the vehicle is on the rolling road.

Error: Confirm the vehicle is safe before closing the work order.

<div class="checkbox">
        <input class="checkbox__input" type="checkbox" id="tyres" name="checks" value="tyres" aria-describedby="tyres-hint">
        <label class="checkbox__label" for="tyres">Tyres checked for wear and pressure</label>
        <p class="checkbox__hint" id="tyres-hint">Minimum tread depth 1.6 mm.</p>
      </div>

      <!-- Invalid single checkbox -->
      <input class="checkbox__input" type="checkbox" id="safe" required aria-invalid="true" aria-describedby="safe-error">

      <!-- Select all: js/checkbox.js keeps checked / indeterminate in sync -->
      <input class="checkbox__input" type="checkbox" id="all" data-select-all aria-controls="v1 v2 v3">

Checkbox group

Which checks were done?

Select all that apply.

Measure pad thickness on both axles.

Fuel type
Which depots should the report include?

Select all that apply.

Error: Select at least one depot.

<fieldset class="fieldset checkbox-group [checkbox-group--horizontal]" aria-describedby="depots-hint depots-error">
        <legend class="fieldset__legend">Which depots should the report include?</legend>
        <p class="field__hint" id="depots-hint">Select all that apply.</p>
        <p class="field__error" id="depots-error">…<span class="sr-only">Error: </span>Select at least one depot.</p>
        <div class="checkbox-group__items">
          <div class="checkbox">…North Yard…</div>
          <div class="checkbox">…Harbour Road…</div>
        </div>
      </fieldset>

API

HookValuesPurpose
.checkbox, .checkbox__input, .checkbox__label, .checkbox__hintblock / partsOne checkbox
.checkbox--smmodifier class20px box for dense tables
.checkbox-group (+ .fieldset), .checkbox-group__itemsblock / partGroup
.checkbox-group--horizontalmodifier classWrapping row of short options
checked, disabled, requiredattributeNative states
aria-invalid="true", :user-invalidattribute / pseudo-classSingle checkbox error
.field__error inside the grouppartGroup error (left rule + red boxes)
data-indeterminate, data-select-all + aria-controlsattribute (js/checkbox.js)Indeterminate and select-all
.is-hover | .is-focus-visibledocs-only classFreezes a state

Do and don't

Vehicle features
Do group related options under a legend that asks the question.
Don't use checkboxes for mutually exclusive answers — use radios.

Accessibility

Keyboard interaction
KeyBehavior
TabMoves to the next checkbox (each is a tab stop)
SpaceToggles the focused checkbox

Tokens

Custom propertyPurpose
--input-border, --input-bgUnchecked box
--color-action-primary-bg | -hover, --color-action-primary-fgChecked box and mark
--color-border-invalidInvalid box, group error rule
--color-bg-muted, --color-text-disabledDisabled
--icon-size-lg | -md, --radius-sm, --border-width-thickBox size and shape
--focus-ring-*Focus