Input & controls
Switch / Toggle
A binary on/off control that usually takes effect immediately.
Also known as toggle · on/off switch · toggle switch
Demo · not production-ready code
Prompt for AI
Pick a stack, copy a ready prompt, paste into Cursor / Claude / ChatGPT.
Your stack
Shapes the prompt you copy
React + Tailwind + shadcn/ui · EN
Stack: React + Tailwind + shadcn/ui. Use React with Tailwind CSS and shadcn/ui patterns (Radix-based primitives, cn(), class-first styling). Task: implement "Switch / Toggle". Replace the checkbox with a switch for the notification setting: role=switch, sliding thumb on a pill track, changes apply immediately with optimistic UI and rollback if the request fails. Anatomy: - track: Pill background that changes with on/off state. - thumb: Sliding knob; animate position, not only color. Preferred API / pattern: `shadcn Switch (Radix)` Keep scope minimal: only this UI pattern, match existing project style.
Acceptance checks
- ○Avoid: Switch that only changes after Save
- ○Avoid: Color-only state with no position change
- ○Avoid: Missing accessible name
In plain wordsHow people search for it
“the little sliding on/off control like iOS settings”“a switch I flip instead of checking a box”“instant on/off for things like Dark mode or notifications”
AnatomyOpen for part names
- track
- Pill background that changes with on/off state.
- thumb
- Sliding knob; animate position, not only color.
How to write itOpen for stack patterns
Web (HTML/CSS)
input type="checkbox" role="switch"React + Tailwind + shadcn/ui
shadcn Switch (Radix)SwiftUI
ToggleAnt Design
<Switch>Notes
Switches are for immediate settings, not multi-select forms (use checkboxes). Label both the purpose and the current state for accessibility. Optimistic UI is fine if you roll back on failure. Don't require a separate Save for a single switch in settings lists.
Common mistakesHumans and models trip here
- Switch that only changes after Save: either use checkbox in a form or apply immediately.
- Color-only state with no position change: move the thumb for clarity.
- Missing accessible name: associate a visible label.
More failure symptoms on AI broke it.
Related patterns
Spotted a wrong name or missing pattern?