Skip to content
Bugwise
Menu
UI Components

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.

30 min Inputs & selection iOS · Android · Web Also called: Switch, Toggle, On/off switch

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

12345
  1. 1

    Track

    The pill-shaped background. Its color shows on (filled) or off (empty).

  2. 2

    Handle (thumb)

    The circle that slides from one side to the other. On Android it grows when switched on.

  3. 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. 4

    Label

    Names the setting in positive words: "Order updates", not "Disable order updates".

  5. 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?

ComponentStatesWhen it takes effectTypical use
Toggle switchOn / offImmediatelySettings: Dark theme, Notifications
CheckboxChecked / unchecked (or mixed)After Submit / SaveForms: “I agree to the terms”, picking several items
Segmented controlOne of 2–5 named optionsImmediatelyTwo options that aren’t on/off: km / miles, List / Map
Radio buttonsOne of severalUsually after SubmitForms: choose a delivery option
ButtonNo lasting stateWhen tappedActions: 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.

Wi-Fi
Low Power Mode

iOS switch

iOS

Green when on, grey when off. In the iOS Settings app only the switch itself reacts; tapping the row text does nothing.

Order updatesRider location, arrival time
Offers & promotions

Material 3 switch

Android

The handle is small when off and grows when on. In Android lists the whole row is tappable.

Use location
Backup over mobile data

Material 3 with icons

Android

A check or a cross inside the handle shows the state without relying on color alone.

Web switch

Web

Usually 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

All

A disabled switch keeps showing its state (on or off) but can't be changed. Tell the user why, if you can.

Allow notifications
Sounds
Badges

Parent and child switches

All

When 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.

Order updates
App showsON
Server hasON

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

Dark theme
Order updatesRider location and arrival time

Flip it and the app changes right away. No Save button needed.

Switches in a form with Submit

anna@example.com
I agree to the Terms of Service
Send me the newsletter
Create account

Did flipping the switch already do something, or only after “Create account”? Users can’t tell. Use checkboxes in forms.

Checkboxes in a form

anna@example.com
I agree to the Terms of Service
Send me the newsletter
Create account

Nothing happens until the user submits. That’s what checkboxes communicate.

Two options that aren't on/off

Metric units

If “Metric units” is off, is it miles? Feet? Name both options with a segmented control instead.

Positive, clear labels

Personalized adsBased on your order history
Email notifications

On means the thing is on. Off means it’s off. No thinking required.

Negative or double-negative labels

Turn off personalized ads
Disable no-reply emails

“Turn off personalized ads: off” means ads are on. Users have to solve a logic puzzle to understand their own settings.

Common bugs

#BugWhat you seeTypical severity
1Silent failureThe switch flips, the request fails (500 or offline), and the switch stays flipped with no messageHigh
2Not persistedThe setting is back to its old value after restarting the app, logging out and in, or on another deviceHigh
3Out of syncThe switch shows “on” but the feature behaves as “off” (e.g. notifications still arrive)High
4Race condition on fast togglingQuick on/off/on taps end in the wrong final state, because responses arrive out of orderMedium
5Dependent switches not disabledChild options stay active while the parent switch (“Push notifications”) is offMedium
6Label does nothingTapping the label or row doesn’t toggle, where the platform says it should (Android rows, web labels)Low–Medium
7Confusing labelNegative or double-negative wording, so users don’t know what “on” meansMedium
8Wrong defaultMarketing or tracking switches default to “on” without consent (a legal risk under GDPR)High
9State shown only by colorUsers with color blindness can’t tell on from off, especially in dark modeMedium
10Screen reader silenceVoiceOver / TalkBack doesn’t say “switch”, “on” or “off”, just the labelHigh (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.

Found0/6
9:41

Settings

Notifications

Push notifications
Order updatesRider location and arrival time
Offers & promotionsDeals from restaurants

Privacy

Share precise locationHelps riders find your door
Turn off personalized ads

Appearance

Dark theme

Test controls

Network log

  • Flip a switch to see API requests…
  1. 1

    Hint: Turn on Server errors, flip a switch, and watch the network log.

  2. 2

    Hint: Turn on Dark theme, then restart the app.

  3. 3

    Hint: Tap the words "Order updates" instead of the switch.

  4. 4

    Hint: Turn off Push notifications, then look at the two switches below.

  5. 5

    Hint: Turn Offers & promotions on and immediately off again. Wait 2 seconds.

  6. 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 restart

Preconditions

  • User is logged in
  • "Order updates" is on

Steps

  1. Open Settings
  2. Turn off "Order updates"
  3. Force-close and reopen the app
  4. Open Settings

Expected result

"Order updates" is off. No order update notifications arrive for the next order.

TC-SW-002Setting syncs to another device

Preconditions

  • Same account logged in on phone A and phone B

Steps

  1. On phone A turn on "Offers & promotions"
  2. 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 error

Preconditions

  • PATCH /api/settings returns 500 (mock or proxy rule)

Steps

  1. Open Settings
  2. 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 offline

Preconditions

  • Airplane mode is on

Steps

  1. Open Settings
  2. Turn on "Dark theme"
  3. 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 state

Preconditions

  • Network throttled to "Slow 3G"

Steps

  1. Tap "Offers & promotions" 5 times quickly (ending on off)
  2. Wait 10 seconds
  3. 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 off

Steps

  1. Open Settings
  2. 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 state

Preconditions

  • TalkBack (Android) or VoiceOver (iOS) is on

Steps

  1. Swipe to the "Dark theme" row
  2. 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 use role="switch" with aria-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> or aria-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) or Toggle (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 with role="switch". (Safari has started supporting a switch attribute 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. 1.A sign-up form has "I agree to the Terms" and a "Create account" button. Which control fits the agreement best?

  2. 2.You turn off "Order updates", the network log shows a 500 error, and the switch stays off. What is the bug?

  3. 3.Which label is clearest for a privacy switch?

  4. 4.What is the most reliable way to check that a switch setting was really saved?

  5. 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 ⚡
Esc

Type to search the whole site.