Skip to content
Fleetline

Switch

Usage

Use a switch for a setting that takes effect immediately — notifications, showing retired vehicles on the map, auto-assigning work orders. Use a checkbox when the choice is only applied after pressing a Save or Submit button.

Anatomy

  1. Track — input[type=checkbox][role=switch].switch__input (native, appearance: none), 44 × 24px
  2. Thumb — ::before, moves to the end when on
  3. Label — label.switch__label[for]
  4. Hint (optional) — .switch__hint

Examples

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

Switch

Only fleet admins can change this.

Drivers get an SMS when their vehicle's service date moves.

Sent to depot managers at 07:00.

<div class="switch [switch--label-start]">
        <input class="switch__input" type="checkbox" role="switch" id="sms" aria-describedby="sms-hint" checked>
        <label class="switch__label" for="sms">Text drivers about schedule changes</label>
        <p class="switch__hint" id="sms-hint">Drivers get an SMS when their vehicle's service date moves.</p>
      </div>

      <!-- Async: while the change is saving -->
      <div class="switch" aria-busy="true">…</div>

API

HookValuesPurpose
.switch, .switch__input, .switch__label, .switch__hintblock / partsOne switch
role="switch"attribute (required)Announced as on/off instead of checked
.switch--label-startmodifier classLabel first, switch at the inline end (settings lists)
checked, disabledattributeOn; not operable (both values shown)
aria-busy="true" on .switchattributeSaving: thumb pulses, pointer input ignored
.is-hover | .is-focus-visibledocs-only classFreezes a state

Do and don't

Do name the setting and let it apply immediately.

Changes apply when you press Save.

Don't label a switch "On/Off" or use it where a Save button applies the change — use a checkbox.

Accessibility

Keyboard interaction
KeyBehavior
TabMoves to the switch
SpaceToggles on/off (native checkbox behavior)

Tokens

Custom propertyPurpose
--color-bg-muted, --input-border, --color-text-mutedOff track, border, thumb
--color-action-primary-bg | -hover, --color-action-primary-fgOn track and thumb
--icon-size-lg, --radius-fullTrack size and shape
--color-bg-subtle, --color-text-disabledDisabled
--motion-duration-fast, --opacity-disabledThumb movement, saving pulse