Skip to content
界面图谱Interface Atlas
☰
中文
ComponentsForm / Input

Switch

开关

Aliases:开关拨动开关切换开关toggle 开关滑动开关开关键

What is it

A thumb sliding on a track represents a binary setting that takes effect immediately, no confirmation needed. Thumb travel and track color change together signal the state, with an on/off text hint beside or inside — the standard control of settings pages.

Interactive playground

Try it. Make an informed choice.

Toggle the switch and inspect the immediate setting state.

Loading lab…

What to look for

  • 01Use switches for immediate settings rather than form submission.
  • 02Keep the label stable and communicate on/off state separately.

✓ When to use

  • Binary settings that apply immediately like notifications or dark mode
  • Changes take visible effect without submitting
  • Settings pages organized around on/off mental models

✕ When not to use

  • Changes need a save step — use a checkbox in a form
  • Selecting several from a list — use checkboxes
  • A third middle state is needed — use a segmented control

Variants

Basic

基础

Bare track without text

With text

带状态文字

On/off text inside for clarity

Settings row

设置行

Title left, switch right — the settings layout

Implementation

transitiontransform: translateXbackgroundborder-radius: 999px

Fixed track width; the thumb translates between ends while the track color crossfades between grey and accent, all durations multiplied by --demo-speed. Express state with role="switch" and aria-checked; make the whole row clickable; hit height at least 32px even if visually smaller. Fade the status text with opacity to avoid jumps.

Platform API

<input type="checkbox" role="switch">

In code

The exact names this thing goes by in each ecosystem — use the row that matches your project.

FrameworkName
ARIArole="switch"
shadcn/uiSwitch
MUISwitch
AntDSwitch

Related concepts

Applicable styles

Sources

Markdown for agents · JSON