Switch

Also known as: Toggle, On/Off switch

Resources

Properties

PropertyValuesDefault
Size Variant2Xs | Xs | SmSm
Selected Booleantrue | falsefalse
State VariantDefault | Hover | Focus | DisabledDefault
Has start icon Booleantrue | falsefalse
Start icon InstanceSwapAny iconheart
Has end icon Booleantrue | falsefalse
End icon InstanceSwapAny iconheart
Has label Booleantrue | falsetrue
Label TextstringLabel
Label position VariantStart | EndEnd

When to use

If users need to make a binary action (on/off, switching color mode or enabling notifications).
When the setting doesn't require confirmation and takes effect immediately.

When multiple switches affect each other in a complex way, leading to confusion.
If user needs to take a non-binary action, such as choosing between "Daily" vs "Weekly" notifications, use radio button instead.

Behaviour

Selection

Switch has two selection states:

  • Use unselected state as default, when the setting is optional and user should enable it themselves or if most users are unlikely to need it on by default.
  • Use selected state as default, when the setting is expected or recommended for must users, it’s a common practice (such as enable notifications), or if the switch represents a system default setting.

States

Switch (and all other forms and selection controls) express states. States indicate current condition of the component to someone interacting with it. Using states ensure clear user feedback, highlighting possible actions or barriers. We have included most common states:

StateContext
DefaultStatus of the component before the interaction. Also referred to as ‘resting’.
HoverWhen the user moves their cursor over the component, but is not taking the action. Slight visual change can indicate interactivity of the component.
FocusWhen user selects the component via keyboard navigation, but has not yet taken action on it.
DisabledA non-interactive state where the component appears faded or grayed out. It indicates that the action is unavailable at the moment.

Size

Dimensions of the switch are tied to the global scale tokens. This ensures that the components, especially forms, with similar size settings remain consistent across the interface. scale tokens also provides more granular control over dimensional settings.

scale.css
--scale-height-<size>
--scale-width-<size>
--scale-icon-size-<size>