Toggle

A sliding on/off control for a setting that takes effect immediately — no separate save; semantically role="switch", with a native checkbox carrying the value and keyboard behavior. When the value is saved with a form, use a checkbox instead.

Sizes

One sm/md/lg dialect. The track height drives width, thumb, and travel at a constant ~1.8:1 stretch; the default is medium.

ExampleSizeModifierTrackUsage
Small--smsize.icon.smDense rows: table cells, compact settings lists
Mediumds-togglesize.icon.mdThe default — forms and settings panels
Large--lgsize.icon.lgTouch targets and high-emphasis settings

States

Real DOM drivers set every state; the demo class forces focus here and behaves identically. There is no hover look — the control is binary and the thumb is its affordance.

ExampleStateDriverRolesUsage
Rest, offborder.strongThe thumb parks left on a neutral track
On:checkedaction.primary.bgsurface.pageThe track carries the primary; the thumb slides right
Focus:focus-visiblefocus.ringKeyboard focus — the shared ring on the track
Disabled:disabledaction.disabled.bgExcluded from interaction and the tab order

Usage notes

A toggle commits immediately — reach for it only when there is no save step.

VerdictRule
DoGive every toggle a label — a visible one via its row, or aria-label when the surrounding text is the label; never rely on position alone.
DoKeep role="switch" on the input so assistive tech announces on/off rather than checked/unchecked.
Don’tUse a toggle where there is a save step — a value committed with a form is a checkbox.
Don’tUse color as the only on/off signal — the thumb position carries the state.
Don’tStretch it past binary — one of several mutually exclusive options is Radio, multi-select in a form is Checkbox.