Selection

Switch

A checkbox with role="switch", drawn as a φ : 1 track whose thumb slides across.

Examples

Switch

Anatomy

labelOptional but recommended. Lines track and text up in a row, as for a checkbox.
> input[type=checkbox][role=switch]The native checkbox with role="switch", no class. The track is φ : 1; the thumb is its ::after.

API

AttributeValuesDescription
roleswitchRequired. Swaps the checkbox box for the track and thumb, and makes screen readers announce on and off.
checkedbooleanFills the track with the accent and slides the thumb to the end.

Accessibility

  • Name the setting, not the action: "Public", not "Make public". The switch announces on or off itself.
  • Use a switch for a setting that applies at once; for a choice that is submitted with a form, use a checkbox.
  • A disabled switch dims and its label turns muted. In right-to-left pages the thumb travels the other way.
KeyEffect
SpaceToggles the switch.
Jump to
ProportionFoundations
MaterialFoundations
PresetsFoundations
ShellLayouts · Application
Container and stacksLayouts · Pages
SplitLayouts · Pages
Grid, bento, masonryLayouts · Pages
Switcher and rowLayouts · Pages
↑↓Move↵OpenescClose