Components · Form

Switch

A switch turns one setting on or off and applies the change at once. It is for a single binary choice, not for picking between options.

Every example on this page is the real component, not a picture. Click, tab and press Space to try it. Figma: Toggle Switch.

Playground

Choose a breakpoint, mode, size, state and value and the switch and its code update. Hover and focus are forced here. The switch is live: click it.

Breakpoint
Mode
Size
State
Value

Markup for this selection

HTML

Overview

A switch turns one setting on or off and applies the change at once. It is for a single binary choice, not for picking between options.

Switch has three sizes (Large, Small, X-Small), a light and a dark mode, and four states, each off and on. It is a native <input type="checkbox" role="switch">, so the keyboard behavior comes from the browser.

This documentation has three pages. Examples & Guidelines (this page) shows when and how to use a switch. Specifications holds the values: tokens, sizes, measurements, states and requirements. Code shows how to add one to a page.


Usage

When to use

Use a switch for one setting that turns on or off, where the change takes effect at once. Use it to:

  • Turn a notification channel on or off
  • Turn a feature or a preference on or off in a list of settings
  • Change a setting in a table row (without a visible label, with an aria-label)

When not to use

When a Save button is needed

A switch applies its change at once, so a list of settings needs no Save button. When the choice is saved on submit, use eco-checkbox.

Do apply the change at once, with no Save button.
Do not pair a switch with a Save button for the same setting.

For a choice between options

To choose between options use eco-radio, and to switch between two related views or filters use eco-pill-segment-control.

Label the setting, not the state

The label names the setting. The switch shows the state, so a label that says “On” or “Off” says it twice and goes out of date when the switch moves.

Do name the setting in the label.
Do not change the label to “On” or “Off”.

Quick reference

The user…Use
turns one setting on or off, with immediate effectSwitch
picks any number of options, saved on submiteco-checkbox
picks exactly one of several optionseco-radio
switches between two related views or filterseco-pill-segment-control

Do

  • Describe the setting in the label, in sentence case.
  • Apply the change immediately.
  • Use .form-switch-item--dark on dark surfaces.
  • Test Space, Tab and label click.

Don’t

  • Pair a switch with a Save button for the same setting.
  • Change the label text to “On” or “Off”.
  • Use a switch to choose between options.
  • Use the dark markup on a light surface.

Anatomy

Switch

  1. Track. A pill, 48×24px (X-Small 32×16px). Grey when off, green when on.
  2. Thumb. A 20px circle (X-Small 12px), 2px from the track edge, with a small shadow. It moves by transform.
  3. Label. body-md (Large) or body-sm, 8px from the track. The whole label is the click target.

The focus ring is 2px with a 2px offset around the track.


Variants

Light and dark mode. Choose the mode to see every example on a light or a dark surface. Sizes are under Sizes below.

Mode
Breakpoint

Settings list

A switch applies its change at once, so a list of settings needs no Save button. The label names the setting; the switch shows the state, so never change the label to “On” or “Off”.

Without a visible label

Only when the setting is named by its surroundings, for example a row in a table. It needs an aria-label.


Sizes

Large and Small have the same 48×24px track and differ only in label size. X-Small (class .form-switch-item--xs) has a 32×16px track for dense layouts. The size does not change with the breakpoint; only the Large label does. Measurements are under Sizes in Specifications.


Layout & Appearance

Alignment

In a list, put the switches on one left edge with the labels after them, one setting per row. Use the same size for every switch in a list.

Appearance

The track is grey when off and green when on, with a white thumb. Use the light version on light surfaces and the dark version (.form-switch-item--dark) on dark ones: surface-100 or surface-80. Token names and values are under Design Tokens in Specifications.


Behavior

Toggling

A click on the switch or the label toggles it, and the change applies at once. Space toggles the focused switch.

Hover and focus

Hover changes the track color. The ring shows with :focus-visible only, for both off and on. All states are listed under States in Specifications.

Disabled

A disabled switch is not focusable. It has a muted track, no thumb shadow and a text-disabled label.

Motion

The track color and the thumb move with a short transition. Reduced motion turns it off. Values are under Motion in Specifications.


Accessibility

All requirements are listed under Accessibility Requirements in Specifications.

Keyboard support

Tab moves between switches. Space toggles the focused one. The focus ring shows with :focus-visible.

Screen reader support

The control is a native input type="checkbox" role="switch" inside a label, so the name, the role and the on/off state are announced. Never build it from a div or a button. A switch without a visible label needs an aria-label.



References