6.11 · UI Pattern

Toggle Switch.

Four styles of toggle: iOS pill, Material square, icon-on-knob, knurled chunky. Click any to flip. All accessible button elements.

What it is

A binary input — on or off — styled as a slider that physically moves between two positions. Often replaces a checkbox in settings panels because the state is immediately clear at a glance (the knob's position) without reading the label. Used universally on settings screens, notification preferences, dark mode controls, feature flags.

How it works

A relative-positioned track (the colored capsule), with an absolutely-positioned knob inside. State toggled via a CSS class (.on) that changes the track background color and transitions the knob's transform: translateX to the other end. Implement as a real <button> with role="switch" and aria-checked for accessibility. Variants differ only by knob shape, track color, and decorative details — the underlying mechanic is the same.

role="switch"ARIA role + aria-checked for screen-reader correctness
transform: translateXKnob slides via transform (GPU-accelerated, no layout reflow)
transition bothTrack color AND knob position transition for smooth flip
Large hit areaMake the wrapper button taller than the visible track for touch

Live demo

Tap any toggle. Each card shows a different style.

Live · click toggles
Notifications
01 — iOS-style pill
Daily digestOne email per morning
MentionsNotify when someone tags you
Weekly summaryActivity recap, Friday afternoons
Privacy
02 — Square / Material
Public profileShow your profile to anyone
Show online statusTell others when you're active
Allow analyticsAnonymous usage metrics
Account
03 — Icon-on-knob
Two-factor authRequired for all sessions
Auto-save draftsSave every 30 seconds
Beta featuresTry new things before they ship
Workshop
04 — Chunky / knurled
Power saverLimit CPU when on battery
Quiet modeMute UI sounds and chimes
Hardware accelUse GPU rendering

Copy this prompt

Prompt · 6.11 Toggle Switch
Build 4 styles of toggle switch, each in a settings card with 3 toggle-row examples. Common mechanics: each toggle is a real 

Example sites to study