What is a toggle switch?
A toggle switch is a control with exactly two states, on and off, that takes effect immediately. There’s no Save button: flipping the switch is the action. It mimics a physical light switch.
You’ll see it used for:
- Device and app settings: Dark theme, Wi-Fi, Face ID for payments.
- Notifications and privacy: Order updates, Share precise location, Personalized ads.
- Turning a feature on or off in place: Show prices with VAT, Auto-play videos.
Anatomy
Order updates
Rider location and arrival time
- 1
Track
The pill-shaped background. Its color shows on (filled) or off (empty).
- 2
Handle (thumb)
The circle that slides from one side to the other. On Android it grows when switched on.
- 3
Icon (optional)
Material 3 can show a check or a cross inside the handle, so the state is not shown by color alone.
- 4
Label
Names the setting in positive words: "Order updates", not "Disable order updates".
- 5
Supporting text (optional)
Explains the effect. On Android the whole row is usually tappable.
Toggle vs checkbox vs segmented control
These three are mixed up all the time. The key question is: does the change happen immediately, or after the user presses a button?
| Component | States | When it takes effect | Typical use |
|---|---|---|---|
| Toggle switch | On / off | Immediately | Settings: Dark theme, Notifications |
| Checkbox | Checked / unchecked (or mixed) | After Submit / Save | Forms: “I agree to the terms”, picking several items |
| Segmented control | One of 2–5 named options | Immediately | Two options that aren’t on/off: km / miles, List / Map |
| Radio buttons | One of several | Usually after Submit | Forms: choose a delivery option |
| Button | No lasting state | When tapped | Actions: Save, Pay, Delete |
Dev note
Apple and Google both call it a switch (UISwitch, SwiftUI Toggle, Material Switch). Designers and web libraries often say toggle. On the web it’s usually a checkbox or button styled to look like a switch, with role="switch".
Designs & variants
Every switch here works. Try tapping the labels too: the platforms behave differently.
iOS switch
iOSGreen when on, grey when off. In the iOS Settings app only the switch itself reacts; tapping the row text does nothing.
Material 3 switch
AndroidThe handle is small when off and grows when on. In Android lists the whole row is tappable.
Material 3 with icons
AndroidA check or a cross inside the handle shows the state without relying on color alone.
Web switch
WebUsually custom-built. It needs role="switch", a label you can click, and a visible focus ring. Press Tab, then Space.
iOS on · off · Android on · off
Disabled
AllA disabled switch keeps showing its state (on or off) but can't be changed. Tell the user why, if you can.
Parent and child switches
AllWhen the main switch is off, the dependent switches become disabled (or hidden). A classic place for bugs.
When does the setting really save?
Most switches change something on a server: your notification preferences, your privacy settings. That’s where the nastiest bugs live. The UI can say one thing while the server stores another.
🧪 When does the setting really save?
A switch talks to a server. Pick a strategy and a network, then flip the switch and compare what the user sees with what the server stored.
Save strategy
Network
The switch flips instantly. If the server fails, it flips back and explains why. The usual choice for toggles.
App and server agree.
- Flip the switch to see requests…
There are two common patterns:
- Optimistic UI: the switch flips instantly and the request is sent in the background. If the request fails, the switch must roll back and tell the user. This feels fast and is the usual choice.
- Pessimistic UI: the switch shows progress and only flips after the server confirms. It’s slower, but makes sense for important settings like Two-factor authentication or Allow card payments abroad.
The bug is the third option nobody plans for: optimistic without rollback. The switch shows on, the server has off, and the user finds out only when they miss an important notification.
Check this part
A sign-up form has "I agree to the Terms" and a "Create account" button. Which control fits the agreement best?
What is the bug in "optimistic UI without rollback"?