Toggle
A toggle is a switch control that lets users turn a setting on or off.
Quarantine
A toggle is a switch control that flips a single setting between two opposing states — on or off — and applies the change immediately. Reach for one when the setting is binary and takes effect the moment it is switched, the way you’d expect a physical light switch to behave. Built on a native <input type="checkbox">, it pairs a sliding thumb with a clear text label so the state reads at a glance.
Anatomy
Section titled “Anatomy”- Switch
- Label
The Switch is a single native control that renders the whole toggle: the pill-shaped track carries the on / off colour, the thumb slides from one end to the other, and an icon inside the thumb — a cross when off, a check when on — repeats the state without relying on colour. The Label names the setting the switch controls.
When to use it
Section titled “When to use it”Use a Toggle when:
- A single setting flips between two opposing states (on / off, enabled / disabled).
- The change takes effect immediately, with no separate Save or Submit step.
- The control adjusts a system or preference setting — notifications, dark mode, Wi-Fi.
Avoid a Toggle when:
- The user picks from a list of non-exclusive options — that’s a Checkbox.
- The choice only applies after submitting a form — a Checkbox reads as “pending” in a way a switch does not.
- More than two states are possible, or the action needs confirmation before it takes effect.
Properties
Section titled “Properties”Track
The pill-shaped background rendered on the native input. It carries the visible on / off state — the neutral emphasis fill when on, a muted fill when off — and mutes to a subtle fill when disabled. The change of colour is never the only cue; it always moves with the thumb.
Thumb
The circular knob that slides across the track. Its position — leading edge for off, trailing edge for on — is the primary, colour-independent signal of the state, so it survives for colour-blind users and in high-contrast modes.
Icon
Sits inside the thumb and repeats the state a third time: a cross when off, a check when on. Decorative — the on / off value is conveyed semantically by the native <input type="checkbox">, not the icon.
State
Rested, Hover, Pressed, Disabled, and Focus, plus an Error treatment via .is-error. Hover and Pressed add a soft outline around the thumb; Focus shows the global focus ring; Disabled mutes the track and drops the control from the tab order. Each state is driven by its own design-token set so it adapts across schemes.
Size
Two sizes — Small and Large. Large is the default for forms and settings; Small is reserved for dense layouts. The label and its clickable region keep the interactive target comfortable in both sizes.
Platform considerations
Section titled “Platform considerations”Desktop
Mouse and keyboard both work — the switch is a single tab stop, toggled with Space. Align the switch with its label on the leading edge and keep the pair on one line so the relationship is obvious.
Tablet
Touch and pointer both apply. Keep the label’s clickable area extended to the full row so a tap anywhere on the line flips the switch without having to hit the thumb precisely.
Mobile
Touch-first. The thumb and its label stay large enough to hit comfortably (≥ 44 px tall). Stack toggles vertically in a settings list; never crowd two switches side by side at narrow widths.
Best practices
Section titled “Best practices”A toggle promises an instant result — make the label describe the setting, and let the switch position and icon, not colour alone, tell the state.
Do
Use a toggle only for binary settings that apply immediately. Label it with the setting it controls (“Notifications”), phrased so “on” is the affirmative. Keep the label visible and next to the switch. Let the thumb position and icon carry the state alongside colour, and show the focus ring on keyboard focus.
Don't
Don’t use a toggle when the change only takes effect after a Save step — that implies a pending state a switch doesn’t have. Don’t use one to pick among a list (that’s a Checkbox) or when only one of several options can be chosen (that’s a Radio). Don’t rely on the track colour alone to signal the state, and don’t replace the visible label with an icon-only control.
Content guidelines
Section titled “Content guidelines”Label the toggle with the setting it controls, not the action it performs — “Notifications” or “Dark mode”, never “Turn on notifications”. Phrase it so the “on” position is the affirmative, matching the switch’s meaning, and use sentence case (“Auto-play videos”). Keep the label short and self-describing; if the setting needs a caveat, put it in supporting text beneath the switch rather than lengthening the label.
Styles
Section titled “Styles”A toggle is a switch control that lets users turn a setting on or off.
<div class="tng-toggle-control"> <input id="c2" type="checkbox" checked /> <label for="c2">On</label></div><div class="tng-toggle-control"> <input id="c1" type="checkbox" /> <label for="c1">Off</label></div><div class="tng-toggle-control"> <input id="c4" type="checkbox" checked disabled /> <label for="c4">On (disabled)</label></div><div class="tng-toggle-control"> <input id="c3" type="checkbox" disabled /> <label for="c3">Off (disabled)</label></div><div class="tng-toggle-control is-error"> <input id="c6" type="checkbox" checked /> <label for="c6">On (error)</label></div><div class="tng-toggle-control is-error"> <input id="c5" type="checkbox" /> <label for="c5">Off (error)</label></div>The toggle follows the WAI-ARIA Switch pattern — a single control that flips a setting between on and off with immediate effect — and meets WCAG 2.1 AA. Built on a native <input type="checkbox">, an accessible toggle is reachable and operable from the keyboard, carries a label that names the setting it controls, and reports its on / off state to assistive technology — so the setting is clear whether the user is looking at it, listening to it, or tabbing through it.
For designers
Section titled “For designers”- All states (default, hover, on, disabled, focus) must maintain accessible contrast on every supported surface. Source: WCAG 1.4.3 Contrast (Minimum).
- The on / off state must never rely on colour alone — pair the colour change with the knob’s position, so the state survives for colour-blind users. Source: WCAG 1.4.1 Use of Color.
- Focus styles must stay visible, meet contrast requirements on every supported surface, and be clearly distinguishable from hover. Source: WCAG 2.4.7 Focus Visible.
- Use semantic colour tokens (e.g.
foreground/neutral/default) rather than fixed values, so the component adapts correctly across themes and surfaces.
For developers
Section titled “For developers”Build on a native <input type="checkbox"> and never recreate the control from <div> or <span> — the native element brings the role, state, and keyboard operability that assistive technology relies on. role="switch" is an optional enhancement on top of that native control, not a replacement for it. A toggle applies its change immediately, so don’t pair it with a Save step that implies the setting is pending. The per-element roles, names, and states are in the Labelling elements section below.
Keyboard interaction
Section titled “Keyboard interaction”| Key | Action |
|---|---|
| Tab / Shift + Tab | Move focus to the next / previous control |
| Space | Toggle the focused switch between on and off |
Interactive targets — the switch plus its label — must be at least 44 px high for comfortable touch use, comfortably clearing the WCAG AA minimum. Source: WCAG 2.5.8 Target Size (Minimum).
Focus order
Section titled “Focus order”A toggle is a single tab stop: focus reaches the switch itself, and its label is associated with the input rather than being a separate stop. The key that drives it is in the Keyboard interaction table above. Source: WCAG 2.4.3 Focus Order.
Labelling elements
Section titled “Labelling elements”Give every element the role, name, and state assistive technology needs.
Switch
A native <input type="checkbox"> exposes the control’s role and its on / off state automatically. Add role="switch" so the state is announced as “on” / “off” — the native checked property carries the value, and the role maps it to aria-checked for you. Convey a non-interactive switch with the native disabled attribute, which also removes it from the tab order. Don’t move state to aria-* when the native attribute already carries it.
Label
The toggle takes its accessible name from the associated <label>, wired with for/id or by wrapping the input. Keep the label visible and self-describing, and phrase it as the setting being controlled (“Notifications”) rather than an action — never leave the name to a title or placeholder, and never replace it with an icon-only control.
Supporting and error text
The .is-error class is a visual cue only. Pair it with aria-invalid="true" and connect the message to the input with aria-describedby, so the failure is announced after the label and conveyed to assistive technology rather than by colour alone.
Source: WCAG 4.1.2 Name, Role, Value.