Skip to content

Signal

Components

Switch

An on/off setting drawn as the iOS switch: role=switch on a checkbox, Accent when on.

Live example

Rendered with the real classes from /site/chitransit.css, light (left) and dark (right).

.ct-switch
checked
disabled

Code

<label class="sd-switch-row">Show line letters <input type="checkbox" role="switch" class="ct-switch"></label>
<label class="sd-switch-row">Train vehicles <input type="checkbox" role="switch" class="ct-switch" checked></label>
<label class="sd-switch-row">Live Activities <input type="checkbox" role="switch" class="ct-switch" checked disabled></label>

Tokens

From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix.

Custom propertyValueAliasResolves to
--ct-switch-background-checkedvar(--accent){colors.accent}#0B4EA2 #92B8F5
--ct-switch-backgroundvar(--switch-track){colors.switchTrack}#838995 #6A7488
--ct-switch-durationvar(--motion-control-duration){motion.controlDuration}.15 s
--ct-switch-heightvar(--size-switch-height){size.switchHeight}31 pt
--ct-switch-radiusvar(--radius-pill){radius.pill}999 pt
--ct-switch-targetvar(--size-minimum-tap-target){size.minimumTapTarget}44 pt
--ct-switch-thumbvar(--size-switch-thumb){size.switchThumb}27 pt
--ct-switch-thumb-shadowvar(--shadow-control){shadows.control}
--ct-switch-widthvar(--size-switch-width){size.switchWidth}51 pt

Contract

Contract: components/switch.yaml. States are drawn live by transit.js.

Variants

One form; no variants. .ct-switch goes on <input type="checkbox" role="switch">; checked and disabled are its only states. Nothing else exists.

<!-- Do -->
<label>Train vehicles <input type="checkbox" role="switch" class="ct-switch" checked></label>
<!-- Don't: a switch between two named options; use a segmented control -->
<label>Minutes or arrival time <input type="checkbox" role="switch" class="ct-switch"></label>

Usage

Do

  • Put the switch at the trailing end of a settings row whose <label> names it, so the row toggles it.
  • Apply the change at once; a switch never needs a Save button.

Don't

  • Don't use a switch for a choice between two named options; use a segmented control.

Accessibility

  • A checkbox input with role="switch" is announced as a switch, on or off.
  • On and off differ by thumb position as well as color.
  • The hit area is at least 44pt through an invisible ::before.