Components · Forms · Switch
Back to Switch typesSwitch
Use for instantly toggling a single setting on or off, like enabling notifications or switching to airplane mode - the change takes effect immediately, with no separate confirm step.
Properties
Size and label are properties of the same component, not separate switches - change them below to check this control's states in the Live Preview. Switches are always fully pill-shaped, so there is no corner-radius property.
Live Preview
Both types compared side by side, each in all 6 states - Hover, Focused and Disabled are demonstrated on top of the Off visual, since a switch is only ever fully Off or fully On; Loading is shown On, since that's the more common case of a setting mid-save. One full matrix is rendered per selected Size.
Try it
The comparison matrix above freezes each state to demonstrate it. This instance is real: click or press Space to toggle it. "Simulate failure" makes the next toggle show Loading, then revert to its previous value and surface the error message above, instead of completing.
When to use
Any single setting that takes effect immediately when flipped, with no need to confirm or submit.
Validation
Switch applies instantly with no submit step, so the usual required/validate-on-submit pattern doesn't apply the way it does to Checkbox - most switches have no "wrong" state to validate.
- Required marking - only add one when a Switch sits inside a form and a specific state must be true before submission, such as a compliance or eligibility toggle - mark it the same way as a required checkbox, not with a separate convention.
- Validation timing - for that in-form case, validate on submit, matching Checkbox.
- Error message - keep it next to that switch's own label, naming what's required, e.g. "You must confirm you're over 18 to continue."
- Standalone settings - a settings-page Switch with no form and no wrong answer has no required or invalid state - don't force validation UI onto it just because the pattern exists elsewhere.
Component Guide
Overview
Switch is for instantly toggling a single, independent setting on or off - the change takes effect immediately with no separate confirm or submit step, unlike a Checkbox inside a form that waits for the whole form to be submitted.
When to Use
- A setting that applies the moment it's flipped - a notification toggle, dark mode.
- A feature flag or experimental setting - turned on/off independently of any form.
- A device-level or system-level toggle - airplane mode.
When Not to Use
- A setting that needs explicit confirmation before it takes effect - use Checkbox plus a Save button, or a confirmation dialog for risky changes.
- More than two states - Switch is strictly binary; use Group Button or Select for three or more options.
- A choice that's part of a larger form submitted together - Checkbox communicates that context more clearly than an instantly-applied Switch.
Best Practices
- Label the setting by its "on" state clearly ("Notifications", not "Enable") so the label reads correctly in both positions.
- Reflect the change immediately in whatever the switch controls, so the user gets instant confirming feedback.
- Avoid using Switch for anything destructive or hard to reverse without pairing it with a follow-up confirmation.
Do and Don't
Do
Named for the setting itself, and it applies the instant it is flipped - no Save step to hunt for.
Don't
A Switch that only takes effect after a separate Save contradicts what a switch promises. Use a Checkbox when the change is submitted with a form.
Accessibility
- Exposed with a real switch or checkbox role, with the current state (on/off) announced to assistive technology.
- The label describes the setting itself, not the mechanism ("Dark mode", not "Toggle switch").
- On/off is never communicated by color alone - the thumb's position and track fill both change too.
Related Components
Checkbox, Radio, Group Button.
{
"component": "Switch",
"category": "Forms",
"summary": "Switch is for instantly toggling a single, independent setting on or off - the change takes effect immediately with no separate confirm or submit step, unlike a Checkbox inside a form that waits for the whole form to be submitted.",
"whenToUse": [
"A setting that applies the moment it's flipped - a notification toggle, dark mode.",
"A feature flag or experimental setting - turned on/off independently of any form.",
"A device-level or system-level toggle - airplane mode."
],
"whenNotToUse": [
"A setting that needs explicit confirmation before it takes effect - use Checkbox plus a Save button, or a confirmation dialog for risky changes.",
"More than two states - Switch is strictly binary; use Group Button or Select for three or more options.",
"A choice that's part of a larger form submitted together - Checkbox communicates that context more clearly than an instantly-applied Switch."
],
"bestPractices": [
"Label the setting by its \"on\" state clearly (\"Notifications\", not \"Enable\") so the label reads correctly in both positions.",
"Reflect the change immediately in whatever the switch controls, so the user gets instant confirming feedback.",
"Avoid using Switch for anything destructive or hard to reverse without pairing it with a follow-up confirmation."
],
"doAndDont": {
"do": "Named for the setting itself, and it applies the instant it is flipped - no Save step to hunt for.",
"dont": "A Switch that only takes effect after a separate Save contradicts what a switch promises. Use a Checkbox when the change is submitted with a form."
},
"accessibility": [
"Exposed with a real switch or checkbox role, with the current state (on/off) announced to assistive technology.",
"The label describes the setting itself, not the mechanism (\"Dark mode\", not \"Toggle switch\").",
"On/off is never communicated by color alone - the thumb's position and track fill both change too."
],
"relatedComponents": [
"Checkbox",
"Radio",
"Group Button"
]
}