Toggle Switch
A two-state control that turns a setting on or off immediately. Learn when to use it instead of a checkbox, how it saves to the server, and how testers catch switches that lie.
Open Settings on any phone and you’ll see a column of little pills: Wi-Fi, Bluetooth, Airplane Mode. Flip one and something happens right away. That’s a toggle switchToggle switchAn on/off control that applies a setting immediately, like Wi-Fi or Dark mode.Open in glossary →.
A switch has only two states, so what could go wrong? Quite a lot: the switch says “on” while the server says “off”, the setting is forgotten after a restart, or the label is so confusing that nobody knows what “on” means. Let’s learn to catch all of that.
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.
When to use it
A toggle switch is the right choice when:
- The setting has two clear states that can be described as on and off.
- The change applies immediately, without a Save button.
- The label names a thing that is on or off: Dark theme, Order updates.
- The user might switch it back and forth, and both states are safe.
Good and bad uses
Instant setting
Flip it and the app changes right away. No Save button needed.
Switches in a form with Submit
Did flipping the switch already do something, or only after “Create account”? Users can’t tell. Use checkboxes in forms.
Checkboxes in a form
Nothing happens until the user submits. That’s what checkboxes communicate.
Two options that aren't on/off
If “Metric units” is off, is it miles? Feet? Name both options with a segmented control instead.
Positive, clear labels
On means the thing is on. Off means it’s off. No thinking required.
Negative or double-negative labels
“Turn off personalized ads: off” means ads are on. Users have to solve a logic puzzle to understand their own settings.
Common bugs
| # | Bug | What you see | Typical severity |
|---|---|---|---|
| 1 | Silent failure | The switch flips, the request fails (500 or offline), and the switch stays flipped with no message | High |
| 2 | Not persisted | The setting is back to its old value after restarting the app, logging out and in, or on another device | High |
| 3 | Out of sync | The switch shows “on” but the feature behaves as “off” (e.g. notifications still arrive) | High |
| 4 | Race condition on fast toggling | Quick on/off/on taps end in the wrong final state, because responses arrive out of order | Medium |
| 5 | Dependent switches not disabled | Child options stay active while the parent switch (“Push notifications”) is off | Medium |
| 6 | Label does nothing | Tapping the label or row doesn’t toggle, where the platform says it should (Android rows, web labels) | Low–Medium |
| 7 | Confusing label | Negative or double-negative wording, so users don’t know what “on” means | Medium |
| 8 | Wrong default | Marketing or tracking switches default to “on” without consent (a legal risk under GDPR) | High |
| 9 | State shown only by color | Users with color blindness can’t tell on from off, especially in dark mode | Medium |
| 10 | Screen reader silence | VoiceOver / TalkBack doesn’t say “switch”, “on” or “off”, just the label | High (for affected users) |
Find the bug
This Android settings screen of a food delivery app has six bugs. Explore it like a tester:
- Flip every switch, then press Restart app. Did everything stick?
- Turn on Server errors and flip switches again.
- Tap the row text, not just the switch.
- Turn off Push notifications and look at the switches below it.
- Flip a switch on and off very quickly. Read every label carefully.
🐞 Bug hunt: Settings screen
This demo has 6 hidden bugs. Explore it like a tester, then check your findings.
Settings
Notifications
Privacy
Appearance
Test controls
Network log
- Flip a switch to see API requests…
- 1
Hint: Turn on Server errors, flip a switch, and watch the network log.
- 2
Hint: Turn on Dark theme, then restart the app.
- 3
Hint: Tap the words "Order updates" instead of the switch.
- 4
Hint: Turn off Push notifications, then look at the two switches below.
- 5
Hint: Turn Offers & promotions on and immediately off again. Wait 2 seconds.
- 6
Hint: Read every label with "on" and "off" after it.
How to test it
Checklist
Toggle switch test checklist
0 of 13 checked
Example test cases
TC-SW-001Turning a setting off is saved and persists after restartpositivehigh
Preconditions
- User is logged in
- "Order updates" is on
Steps
- Open Settings
- Turn off "Order updates"
- Force-close and reopen the app
- Open Settings
Expected result
"Order updates" is off. No order update notifications arrive for the next order.
TC-SW-002Setting syncs to another devicepositivemedium
Preconditions
- Same account logged in on phone A and phone B
Steps
- On phone A turn on "Offers & promotions"
- On phone B open Settings (pull to refresh if available)
Expected result
"Offers & promotions" is on on phone B.
TC-SW-003Switch rolls back when the server returns an errornegativehigh
Preconditions
- PATCH /api/settings returns 500 (mock or proxy rule)
Steps
- Open Settings
- Turn off "Share precise location"
Expected result
The switch returns to on within a few seconds and an error message is shown. Restarting the app shows on.
TC-SW-004Changing a setting while offlinenegativemedium
Preconditions
- Airplane mode is on
Steps
- Open Settings
- Turn on "Dark theme"
- Turn off "Order updates"
Expected result
Local-only settings (Dark theme) apply. Server settings either roll back with an "You're offline" message or are clearly queued and saved when the connection returns.
TC-SW-005Rapid toggling ends in the last selected stateedgemedium
Preconditions
- Network throttled to "Slow 3G"
Steps
- Tap "Offers & promotions" 5 times quickly (ending on off)
- Wait 10 seconds
- Restart the app
Expected result
The switch is off before and after restart. The last request sent has offers=false and the server stores false.
TC-SW-006Child settings are disabled when the parent is offpositivemedium
Steps
- Open Settings
- Turn off "Push notifications"
Expected result
"Order updates" and "Offers & promotions" are greyed out and cannot be changed. Turning push back on restores their previous values.
TC-SW-007Screen reader announces role and statepositivemedium
Preconditions
- TalkBack (Android) or VoiceOver (iOS) is on
Steps
- Swipe to the "Dark theme" row
- Double-tap to toggle
Expected result
Announces "Dark theme, switch, off", then "on" after double-tapping.
Tip: click a test case to expand it.
Accessibility
- Role and state: Screen readersScreen readerSoftware that reads the screen aloud for blind and low-vision users, like VoiceOver or TalkBack.Open in glossary → must announce the label, the role (“switch” or “toggle button”) and the state (“on”/“off”).
Dev note
On the web userole="switch"witharia-checked, or a native<input type="checkbox" role="switch">. - A real label: the switch must be connected to its visible label, not just placed next to it. Otherwise VoiceOver says only “switch, on”. For what?
Dev note
<label for>oraria-labelledby. - Not color alone: the handle position already helps; Material’s check/cross icons and iOS’s optional on/off labels (Settings › Accessibility › Display & Text Size › On/Off Labels) help more. Check contrast of the track and handle: at least 3:1 against the background.
- Touch targetTouch targetThe area of the screen that responds to a tap, which should be large enough for a finger.Open in glossary →: at least 44×44 pt on iOS and 48×48 dp on Android. On the web, WCAG 2.5.8 (AA) asks for at least 24×24 CSS px; 44×44 px (2.5.5, AAA) is the comfortable target. A whole tappable row is even better.
- Keyboard (web): Tab reaches the switch, Space toggles it, and the focus ring is visible.
- Announce failures: if a save fails and the switch rolls back, announce the error message too, or screen reader users will never know.
Mobile vs web
- Green track when on, grey when off. The color can be customized, so check contrast.
Dev note
Native:UISwitch(UIKit) orToggle(SwiftUI). - In grouped Settings-style lists, the switch sits on the right; tapping the row text usually does nothing.
- Optional On/Off Labels accessibility setting shows I/O marks on the switch. Test with it on.
- VoiceOver reads “Label, switch button, on”. Double-tap toggles.
- Material 3 switch: the handle grows when on, and can show check / cross icons. The whole list row is usually tappable.
- Test with TalkBack, font scale and display size, plus dark theme (the colors change completely).
- Watch for process death: Android may kill the app in the background. Coming back, are the switches still correct?
- Older apps may still use Material 2 switches: a thin track with a larger round handle. Mixed styles on one screen are a visual bug.
- No cross-browser HTML switch element, so quality varies. Inspect it in DevToolsDevToolsDeveloper tools built into browsers for inspecting pages, network traffic and errors.Open in glossary →.
Dev note
It’s built from a checkbox or a button withrole="switch". (Safari has started supporting aswitchattribute on checkboxes, but other browsers don’t yet.) - Check that clicking the label toggles it, that Space works, and that the focus ring is visible.
- Use DevTools to throttle or block the settings request and check rollback and error messages.
- Inside forms, ask: does this switch save immediately, or only when the form is submitted? If the answer is “on submit”, it should probably be a checkbox.
Check your understanding
Quick quiz
0/5 answered · 0 correct
1.A sign-up form has "I agree to the Terms" and a "Create account" button. Which control fits the agreement best?
2.You turn off "Order updates", the network log shows a 500 error, and the switch stays off. What is the bug?
3.Which label is clearest for a privacy switch?
4.What is the most reliable way to check that a switch setting was really saved?
5.A user wants to choose between kilometers and miles. What should the design use?
Key takeaways
- A toggle switch has two states and takes effect immediately. In forms that need Submit, use checkboxes.
- If both options have names (km / miles), use a segmented control, not a switch.
- Labels must be positive: on means the named thing is on.
- The screen and the server are two copies of the setting. Test failed saves (rollback + message), restarts, second devices and fast toggling.
- Check dependent switches, label/row tapping, color-independent state, and screen reader announcements.
Finished this page?Nice work, this page is complete!
Mark it as done to track your progress. It's saved in this browser, no account needed.
Its review cards are now in Bites ⚡