Skip to main content
InputLevel 1

Switch

开关

WebMobileDesktopDifficulty: Easy

A control that slides left and right, on or off, with the state always plainly visible.

01

Live Demo

Actually clickable
A switch takes effect immediately — note how it differs from a checkbox: a Switch changes state, it doesn't collect a choice.

What you just saw:The slider at the right end of a "Dark mode" or "Notifications" row in Settings, every green rounded switch in iOS Settings, the "Autoplay video" toggle in an app preferences screen.

02

What it actually is

A switch communicates whether a feature is currently on. The difference from a checkbox is a difference in tense: a checkbox says "you ticked this action", a switch says "this state is on". A checkbox usually takes effect on submit; a switch takes effect immediately.

switchtoggle switchtoggleon-off switchflip switchswitch control
03

Anatomy · What it's made of

  1. Track轨道

    40×24px, turns the primary color when on

  2. Thumb滑块

    A 20px circle that lifts with a shadow while dragging

  3. Label文字

    Describes the feature, not the state

  4. State Label状态文字

    Optional, reads "On / Off"

04

When to Use

When it fits, and when it doesn't
Switch usage recommendations
SituationUse it?
A feature is on or off and the change takes effect immediatelyYes
The current state must be visible at a glanceYes
The state itself carries meaning (on = power-saving mode)Yes
The change should only take effect after confirmationNo
The selection has to be submitted along with a formDepends

A switch should not need a tooltip explaining what "on" and "off" mean — if it does, use a checkbox with explicit copy instead.

When flipping it has serious consequences (turning it off loses data), pair the switch with a confirmation or an undo.

05

Similar Patterns

Don't mix these up
Full comparisonCheckbox vs Radio vs SwitchI need the user to make a selection. Which control?See the table
06

How to tell AI

Three levels of prompt

Add the component name and specifics

Add a settings row: the title "Dark mode" plus a line of description on the left, a switch on the right. Toggling takes effect immediately and confirms with a toast.

07

Don't just say this to AI

Bad → Better

Don't say this to AI

Add something that can be turned on and off.

Say this instead

Add a Switch settings row: role="switch" + aria-checked, a 44×26px track, a 22px thumb, the change takes effect immediately with a confirmation toast, the whole row is tappable, and it does not use checkbox semantics.

08

Share this card

Social-ready

Turn this pattern into a 3:4 or 1:1 knowledge card and export it as PNG right in the browser. No backend needed.