47 Tailwind CSS Toggles & Switches
06 / 47

All 47 in 47 Tailwind CSS Toggles & Switches

  1. 01Tailwind iOS-Style Toggle Switch with appearance-none
  2. 02Tailwind Dark Mode Sun / Moon Theme Switcher
  3. 03Tailwind Neumorphic Soft-UI Pill Toggle
  4. 04Tailwind Gooey Liquid Morphing Switch with SVG Filter
  5. 05Tailwind Bouncy Elastic Physics Toggle (Overshoot Cubic-Bezier)
  6. 06Tailwind ON / OFF Text Switch with Labels Inside the Track
  7. 07Tailwind SaaS Pricing Toggle — Monthly / Annually Segmented Pill
  8. 08Tailwind Mechanical Keycap Toggles with Haptic Feedback
  9. 09Tailwind Waveform Mute Toggle with Animated EQ Bars
  10. 10Tailwind Timed Auto-Off Toggle with Conic Countdown Ring
  11. 11Tailwind Press-and-Hold to Confirm Toggle (Fingerprint Scan)
  12. 12Tailwind Split-Flap Departure Board Toggle (3D Flip)
  13. 13Tailwind Permission Toggle Group with :has() Live Status Badge
  14. 14Tailwind Material Design 3 Switch with State Layer
  15. 15Tailwind Skeuomorphic Wall Light Switch with Room Relight
  16. 16Tailwind Neon Cyberpunk Toggle with Clipped Corners
  17. 17Tailwind Brutalist Snap Toggle with Hard Offset Shadow
  18. 18Tailwind Day / Night Landscape Scene Switch
  19. 19Tailwind 3D Flip Card Toggle (rotateY Switch)
  20. 20Tailwind Sliding Pill Toggle with Label Inside the Thumb
  21. 21Tailwind Glassmorphism Frosted Toggle with backdrop-blur
  22. 22Tailwind Rotary Knob Toggle with Brushed-Metal Conic Gradient
  23. 23Tailwind iOS Settings List with Grouped Toggle Rows
  24. 24Tailwind Minimal Outline Toggle Drawn in currentColor
  25. 25Tailwind Squash-and-Stretch Pebble Toggle
  26. 26Tailwind Industrial Rocker I/O Power Switch
  27. 27Tailwind Accessible role=switch Toggle with forced-colors Support
  28. 28Tailwind Macro-Pad Toggle Grid with RGB Underglow
  29. 29Tailwind Radial VU Meter Mute Toggle
  30. 30Tailwind Segmented Pip Countdown Auto-Off Toggle
  31. 31Tailwind Slide-to-Confirm Toggle Rail (Drag or Arrow Keys)
  32. 32Tailwind Odometer Roll ON / OFF Toggle
  33. 33Tailwind Master Toggle with Indeterminate Tri-State
  34. 34Tailwind iOS Control Centre Tile Toggles
  35. 35Tailwind Material 3 Connected Icon Toggle Buttons
  36. 36Tailwind Two-Gang Wall Plate with Cumulative Room Light
  37. 37Tailwind Neon Toggle with Animated Conic Border Light
  38. 38Tailwind Brutalist Rubber-Stamp Toggle
  39. 39Tailwind Aurora Night Sky Toggle Switch
  40. 40Tailwind 3D Rotating Cube Toggle
  41. 41Tailwind Three-Position Off / Auto / On Selector
  42. 42Tailwind Liquid Glass Toggle with Specular Highlight
  43. 43Tailwind Three-Detent Rotary Selector Knob
  44. 44Tailwind Hardware Slide Switch with Knurled Grip
  45. 45Tailwind Battery Saver Toggle with Live Fill Meter
  46. 46Tailwind Morphing Sun-to-Moon Icon Toggle (SVG Stroke)
  47. 47Tailwind Guarded Kill Switch Under a Flip-Up Safety Cover
Pure TailwindMIT licensed

Tailwind ON / OFF Text Switch with Labels Inside the Track

State spelled out, not inferred: ON and OFF live inside a 96px track, the thumb covers the inactive word, and the active one fades in. The port is a peer masterclass — one sr-only checkbox drives a track, two words and a thumb, all through peer-checked:.

Live Demo
Plain CSSTailwind v4
Try it

Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time

Untitled UI React · Affiliate link

Get Untitled UI Pro

The code

<section class="ttg-06 w-full min-h-svh flex flex-col items-center justify-center gap-7 px-5 py-14 bg-ttg06-bg font-ttg06-sans" aria-label="Text labelled ON OFF switch">
  <div class="flex items-center gap-8 px-7 py-5 rounded-3xl bg-white border border-ttg06-edge shadow-[0_18px_40px_-30px_oklch(0.4_0.05_265/0.5)]">
    <span class="flex flex-col gap-0.5">
      <span id="ttg-06-l" class="text-[15.5px] font-semibold text-ttg06-ink">Maintenance mode</span>
      <span class="text-[12.5px] text-ttg06-mute">Serves a status page to every visitor</span>
    </span>
    <input type="checkbox" id="ttg-06-sw" role="switch" aria-labelledby="ttg-06-l" class="peer sr-only">
    <label for="ttg-06-sw" aria-hidden="true" class="relative shrink-0 w-24 h-10 rounded-full bg-ttg06-off cursor-pointer transition-colors duration-300 text-[12.5px] font-extrabold tracking-[0.08em] text-white peer-checked:bg-ttg06-on peer-focus-visible:outline-3 peer-focus-visible:outline-ttg06-focus peer-focus-visible:outline-offset-3 peer-checked:[&_.ttg06-on]:opacity-100 peer-checked:[&_.ttg06-on]:translate-x-0 peer-checked:[&_.ttg06-off]:opacity-0 peer-checked:[&_.ttg06-off]:translate-x-1.5 peer-checked:[&_.ttg06-thumb]:translate-x-14">
      <span class="ttg06-on absolute inset-y-0 left-4 flex items-center opacity-0 -translate-x-1.5 transition-[opacity,transform] duration-300 motion-reduce:transition-opacity">ON</span>
      <span class="ttg06-off absolute inset-y-0 right-3.5 flex items-center opacity-100 transition-[opacity,transform] duration-300 motion-reduce:transition-opacity">OFF</span>
      <span class="ttg06-thumb absolute top-1 left-1 w-8 h-8 rounded-full bg-white shadow-[0_2px_6px_oklch(0.35_0.04_265/0.35)] transition-transform duration-300 ease-[cubic-bezier(0.25,0.9,0.3,1.1)] motion-reduce:duration-100"></span>
    </label>
  </div>
  <p class="font-ttg06-mono text-[11px] tracking-[0.14em] uppercase text-ttg06-mute">State in words, not just colour</p>
</section>
@import "tailwindcss";

@theme {
  --color-ttg06-bg: #f3f4f8;
  --color-ttg06-bg: oklch(0.96 0.005 265);
  --color-ttg06-edge: #e6e7ef;
  --color-ttg06-edge: oklch(0.93 0.006 265);
  --color-ttg06-off: #6b7385;
  --color-ttg06-off: oklch(0.55 0.02 265);
  --color-ttg06-on: #2f8f5b;
  --color-ttg06-on: oklch(0.58 0.14 155);
  --color-ttg06-ink: #262b36;
  --color-ttg06-ink: oklch(0.28 0.012 265);
  --color-ttg06-mute: #868c9b;
  --color-ttg06-mute: oklch(0.62 0.015 265);
  --color-ttg06-focus: #4665e8;
  --color-ttg06-focus: oklch(0.55 0.19 265);
  --font-ttg06-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-ttg06-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

.ttg-06 {
  width: 100%;
  min-height: 100svh;
}

Setup — do this once per project

Skip this if your project already runs Tailwind v4.

1Load Tailwind
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Compiles in the browser — perfect for a CodePen or a quick test, not for production.

2Add the stylesheetRequiredthe @theme block is what makes the custom utilities exist
@import "tailwindcss";

@theme {
  --color-ttg06-bg: #f3f4f8;
  --color-ttg06-bg: oklch(0.96 0.005 265);
  --color-ttg06-edge: #e6e7ef;
  --color-ttg06-edge: oklch(0.93 0.006 265);
  --color-ttg06-off: #6b7385;
  --color-ttg06-off: oklch(0.55 0.02 265);
  --color-ttg06-on: #2f8f5b;
  --color-ttg06-on: oklch(0.58 0.14 155);
  --color-ttg06-ink: #262b36;
  --color-ttg06-ink: oklch(0.28 0.012 265);
  --color-ttg06-mute: #868c9b;
  --color-ttg06-mute: oklch(0.62 0.015 265);
  --color-ttg06-focus: #4665e8;
  --color-ttg06-focus: oklch(0.55 0.19 265);
  --font-ttg06-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-ttg06-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

.ttg-06 {
  width: 100%;
  min-height: 100svh;
}
3Fonts used by this demooptional — skip if you have your own type stack
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap">

What changed in the port

Which parts became utilities, which stayed CSS, and why.

  • This is the demo that justifies peer. One marker class on the input, and the track, both words and the thumb all read its state — the CSS original needed five separate ~ selectors, each repeating the input's class name.
  • peer-checked:[&_.ttg06-on]:opacity-100 reads awkwardly but is exact: peer-checked: supplies .peer:checked ~ & and the arbitrary descendant selector supplies the rest. The alternative — putting peer-checked: on each inner span — does not work, because they are descendants of the sibling, not siblings themselves.
  • peer-focus-visible: is the accessibility-critical variant in the whole collection: the input is invisible, so the ring must be drawn on the track the user can see.
  • UI change from the CSS original: both state colours were darkened for white text — OFF from #7c8494 (2.9:1) to oklch(0.55 0.02 265) (5.3:1) and ON to oklch(0.58 0.14 155) (4.6:1) — because a switch whose entire point is a readable word had unreadable words.
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS demo from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Tailwind ON / OFF Text Switch with Labels Inside the Track
Source: https://codefronts.com/components/tailwind-css-toggles-switches/tailwind-on-off-text-switch-labels-inside-track/

State spelled out, not inferred: ON and OFF live inside a 96px track, the thumb covers the inactive word, and the active one fades in. The port is a peer masterclass &mdash; one sr-only checkbox drives a track, two words and a thumb, all through peer-checked:.
## HTML
```html
<section class="ttg-06 w-full min-h-svh flex flex-col items-center justify-center gap-7 px-5 py-14 bg-ttg06-bg font-ttg06-sans" aria-label="Text labelled ON OFF switch">
  <div class="flex items-center gap-8 px-7 py-5 rounded-3xl bg-white border border-ttg06-edge shadow-[0_18px_40px_-30px_oklch(0.4_0.05_265/0.5)]">
    <span class="flex flex-col gap-0.5">
      <span id="ttg-06-l" class="text-[15.5px] font-semibold text-ttg06-ink">Maintenance mode</span>
      <span class="text-[12.5px] text-ttg06-mute">Serves a status page to every visitor</span>
    </span>
    <input type="checkbox" id="ttg-06-sw" role="switch" aria-labelledby="ttg-06-l" class="peer sr-only">
    <label for="ttg-06-sw" aria-hidden="true" class="relative shrink-0 w-24 h-10 rounded-full bg-ttg06-off cursor-pointer transition-colors duration-300 text-[12.5px] font-extrabold tracking-[0.08em] text-white peer-checked:bg-ttg06-on peer-focus-visible:outline-3 peer-focus-visible:outline-ttg06-focus peer-focus-visible:outline-offset-3 peer-checked:[&_.ttg06-on]:opacity-100 peer-checked:[&_.ttg06-on]:translate-x-0 peer-checked:[&_.ttg06-off]:opacity-0 peer-checked:[&_.ttg06-off]:translate-x-1.5 peer-checked:[&_.ttg06-thumb]:translate-x-14">
      <span class="ttg06-on absolute inset-y-0 left-4 flex items-center opacity-0 -translate-x-1.5 transition-[opacity,transform] duration-300 motion-reduce:transition-opacity">ON</span>
      <span class="ttg06-off absolute inset-y-0 right-3.5 flex items-center opacity-100 transition-[opacity,transform] duration-300 motion-reduce:transition-opacity">OFF</span>
      <span class="ttg06-thumb absolute top-1 left-1 w-8 h-8 rounded-full bg-white shadow-[0_2px_6px_oklch(0.35_0.04_265/0.35)] transition-transform duration-300 ease-[cubic-bezier(0.25,0.9,0.3,1.1)] motion-reduce:duration-100"></span>
    </label>
  </div>
  <p class="font-ttg06-mono text-[11px] tracking-[0.14em] uppercase text-ttg06-mute">State in words, not just colour</p>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-ttg06-bg: #f3f4f8;
  --color-ttg06-bg: oklch(0.96 0.005 265);
  --color-ttg06-edge: #e6e7ef;
  --color-ttg06-edge: oklch(0.93 0.006 265);
  --color-ttg06-off: #6b7385;
  --color-ttg06-off: oklch(0.55 0.02 265);
  --color-ttg06-on: #2f8f5b;
  --color-ttg06-on: oklch(0.58 0.14 155);
  --color-ttg06-ink: #262b36;
  --color-ttg06-ink: oklch(0.28 0.012 265);
  --color-ttg06-mute: #868c9b;
  --color-ttg06-mute: oklch(0.62 0.015 265);
  --color-ttg06-focus: #4665e8;
  --color-ttg06-focus: oklch(0.55 0.19 265);
  --font-ttg06-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-ttg06-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

.ttg-06 {
  width: 100%;
  min-height: 100svh;
}
```

How this works

Everything hangs off peer. The checkbox is sr-only (clipped, not display:none, so it keeps its place in the tab order) and carries the peer marker. Every visible part of the switch is a later sibling or a descendant of one, so peer-checked: and peer-focus-visible: reach all of it without a line of JavaScript.

The words are decoration; the label is the name. The visible track is aria-hidden and the accessible name comes from the real label text beside it, bound with aria-labelledby. A screen reader announces "Maintenance mode, switch, on" — it never reads a stray "ON OFF".

Two crossfades, one thumb. ON starts at opacity-0 -translate-x-1.5 and OFF at full opacity; checking swaps them while the thumb travels 56px. The drift is what sells it: without the 6px translate the words simply blink.

Make it yours

  • Localise freely — YES/NO, I/O, LIVE/OFF. Widen the track if the longest word grows, and adjust the thumb travel to match.
  • Give each state its own track colour for faster scanning in dense settings lists.
  • Drop the translate-x drift for a calmer read; keep the opacity crossfade.
  • Bold the active word only, reinforcing state for users who cannot rely on the colour.

Gotchas — read before shipping

  • sr-only is the right hiding utility; hidden removes the control from the tab order entirely and is the single most common way this pattern is broken.
  • peer only reaches LATER siblings. The input must come before the track in source order — reorder them and the whole demo silently stops working.
  • Size the track to the longest word plus thumb travel. A truncated state word is worse than no word at all.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

Sibling :checked styling and transforms are universal; this demo has no modern-CSS requirement beyond Tailwind v4's own generated sheet.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Search CodeFronts

Loading…