Skip to main content

Switch

A switch allows users to select between one of two opposing states or options.

Code documentation

Web

Anatomy

The switch component is made up of four elements.

Anatomy diagram numbering four elements of a switch.
  1. Thumb
  2. Track
  3. Helper text
  4. Label

Variants

Label

Labels are not required if an adjacent label is included that adequately describes the purpose of the switch and is correctly referenced to the field for accessibility purposes.

A switch with no label.

State text

Use text that matches what the switch means. "On" / "Off" when it turns something on or off, "Yes" / "No" when the label reads as a statement or question.

Helper text

Helper text can be included alongside the label to provide additional context or guidance for using the control.

A switch includes sample helper text immediately below the label. Both are positioned to the right of the switch.

Behavior

Text overflow

When labels wrap to multiple lines, the first line of the text remains vertically centered with the control. Helper text simply wraps to the next line.

The switch's label and helper text each wrap to multiple lines when they meet the edge of an implied container around the switch.

States

Switches can be either unselected or selected. Each of those statuses has five states:

  1. Enabled
  2. Focus
  3. Hover
  4. Active
  5. Disabled
The unselected switch includes enabled, focus, hover, active, and disabled states.
Unselected
The selected switch includes enabled, focus, hover, active, and disabled states.
Selected

Read-only

A switch is a control. When a value can't be edited, don't show a switch.

Read-only views. On a summary or detail screen where nothing is editable, show the value as text next to its label, the same text the switch would show: "On" / "Off" or "Yes" / "No".

Locked settings. In an editable form where this one setting can't be changed right now (permissions, or a dependency on another field), use a disabled switch and explain why nearby.

Don't use icons such as a check or an X for the value. They read as success and error, and they rely on color.