47 Tailwind CSS Toggles & Switches
44 / 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 Hardware Slide Switch with Knurled Grip

The mute slider off the side of a phone: a knurled grip that slides in a machined channel and reveals a painted orange band behind it. No thumb glides — it travels in a slot, and the colour underneath is what tells you the state.

Live Demo
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-44 w-full min-h-svh flex flex-col items-center justify-center gap-8 px-5 py-14 bg-ttg44-bg font-ttg44-sans" aria-label="Hardware slide switch">
  <label for="ttg-44-sw" class="flex items-center gap-9 px-8 py-6 rounded-[20px] cursor-pointer bg-linear-165 from-ttg44-chassishi to-ttg44-chassislo shadow-[0_24px_50px_-26px_oklch(0_0_0/0.9),inset_0_1px_0_oklch(1_0_0/0.09)] has-checked:[&_.ttg44-state]:text-ttg44-paint">
    <span class="flex flex-col gap-0.5">
      <b class="text-[15.5px] font-semibold text-ttg44-ink">Ringer</b>
      <span class="ttg44-state text-[12.5px] text-ttg44-mute transition-colors duration-200">Slide down to silence</span>
    </span>
    <span class="relative shrink-0 w-[74px] h-11 rounded-[13px] overflow-hidden bg-ttg44-channel shadow-[inset_0_2px_5px_oklch(0_0_0/0.75),inset_0_0_0_1px_oklch(0_0_0/0.5)]">
      <span aria-hidden="true" class="absolute inset-y-1.5 left-1.5 w-8 rounded-lg bg-ttg44-paint shadow-[inset_0_1px_2px_oklch(0_0_0/0.35)]"></span>
      <input type="checkbox" id="ttg-44-sw" role="switch" aria-label="Silent mode" class="peer appearance-none absolute inset-0 w-full h-full bg-transparent cursor-pointer z-20 focus-visible:outline-3 focus-visible:outline-ttg44-focus focus-visible:outline-offset-4">
      <span aria-hidden="true" class="ttg44-grip pointer-events-none absolute top-1 left-1 z-10 w-9 h-9 rounded-[10px] bg-linear-to-b from-ttg44-griphi to-ttg44-griplo shadow-[0_2px_5px_oklch(0_0_0/0.6),inset_0_1px_0_oklch(1_0_0/0.45)] transition-transform duration-150 ease-out peer-checked:translate-x-[30px] motion-reduce:transition-none">
        <i class="absolute inset-y-2 inset-x-1.5 rounded-sm opacity-70 [background:repeating-linear-gradient(90deg,var(--color-ttg44-ridgehi)_0_1px,var(--color-ttg44-ridgelo)_1px_3px)]"></i>
      </span>
    </span>
  </label>
  <p class="text-[11px] tracking-[0.16em] uppercase text-ttg44-mute">Orange showing = silent</p>
</section>
@import "tailwindcss";

@theme {
  --color-ttg44-bg: #1b1d21;
  --color-ttg44-bg: oklch(0.23 0.005 265);
  --color-ttg44-chassishi: #3a3e45;
  --color-ttg44-chassishi: oklch(0.36 0.007 265);
  --color-ttg44-chassislo: #2b2e34;
  --color-ttg44-chassislo: oklch(0.3 0.006 265);
  --color-ttg44-channel: #17191d;
  --color-ttg44-channel: oklch(0.2 0.005 265);
  --color-ttg44-paint: #f07a2a;
  --color-ttg44-paint: oklch(0.7 0.18 50);
  --color-ttg44-griphi: #e6e9ef;
  --color-ttg44-griphi: oklch(0.93 0.006 265);
  --color-ttg44-griplo: #b7bcc6;
  --color-ttg44-griplo: oklch(0.79 0.008 265);
  --color-ttg44-ridgehi: #ffffff;
  --color-ttg44-ridgehi: oklch(1 0 0 / 0.75);
  --color-ttg44-ridgelo: #8d929c;
  --color-ttg44-ridgelo: oklch(0.65 0.01 265 / 0.6);
  --color-ttg44-ink: #e4e7ee;
  --color-ttg44-ink: oklch(0.92 0.006 265);
  --color-ttg44-mute: #949aa6;
  --color-ttg44-mute: oklch(0.68 0.012 265);
  --color-ttg44-focus: #6cb6f0;
  --color-ttg44-focus: oklch(0.74 0.14 235);
  --font-ttg44-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}

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

.ttg-44 input[type="checkbox"] {
  -webkit-appearance: none;
}

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-ttg44-bg: #1b1d21;
  --color-ttg44-bg: oklch(0.23 0.005 265);
  --color-ttg44-chassishi: #3a3e45;
  --color-ttg44-chassishi: oklch(0.36 0.007 265);
  --color-ttg44-chassislo: #2b2e34;
  --color-ttg44-chassislo: oklch(0.3 0.006 265);
  --color-ttg44-channel: #17191d;
  --color-ttg44-channel: oklch(0.2 0.005 265);
  --color-ttg44-paint: #f07a2a;
  --color-ttg44-paint: oklch(0.7 0.18 50);
  --color-ttg44-griphi: #e6e9ef;
  --color-ttg44-griphi: oklch(0.93 0.006 265);
  --color-ttg44-griplo: #b7bcc6;
  --color-ttg44-griplo: oklch(0.79 0.008 265);
  --color-ttg44-ridgehi: #ffffff;
  --color-ttg44-ridgehi: oklch(1 0 0 / 0.75);
  --color-ttg44-ridgelo: #8d929c;
  --color-ttg44-ridgelo: oklch(0.65 0.01 265 / 0.6);
  --color-ttg44-ink: #e4e7ee;
  --color-ttg44-ink: oklch(0.92 0.006 265);
  --color-ttg44-mute: #949aa6;
  --color-ttg44-mute: oklch(0.68 0.012 265);
  --color-ttg44-focus: #6cb6f0;
  --color-ttg44-focus: oklch(0.74 0.14 235);
  --font-ttg44-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}

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

.ttg-44 input[type="checkbox"] {
  -webkit-appearance: none;
}
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&display=swap">

What changed in the port

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

  • Revealing a painted band rather than recolouring a track is the port's idea, not a technique: it costs one absolutely-positioned span and it is the entire reason the control reads as a physical object.
  • The knurl is [background:repeating-linear-gradient(90deg,var(--color-ttg44-ridgehi)_0_1px,var(--color-ttg44-ridgelo)_1px_3px)] at 70% opacity over the grip's own gradient — texture layered on shading, which is how real machined surfaces read.
  • duration-150 ease-out with no overshoot anywhere. This is the one demo in the collection where a spring curve would be a bug.
  • UI upgrade over demo 26: the state is revealed rather than repainted, the supporting line changes colour AND wording so the meaning of the orange band is stated in text, and the caption explains the convention for anyone who has never held the hardware it imitates.
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 Hardware Slide Switch with Knurled Grip
Source: https://codefronts.com/components/tailwind-css-toggles-switches/tailwind-hardware-slide-switch-knurled-grip/

The mute slider off the side of a phone: a knurled grip that slides in a machined channel and reveals a painted orange band behind it. No thumb glides &mdash; it travels in a slot, and the colour underneath is what tells you the state.
## HTML
```html
<section class="ttg-44 w-full min-h-svh flex flex-col items-center justify-center gap-8 px-5 py-14 bg-ttg44-bg font-ttg44-sans" aria-label="Hardware slide switch">
  <label for="ttg-44-sw" class="flex items-center gap-9 px-8 py-6 rounded-[20px] cursor-pointer bg-linear-165 from-ttg44-chassishi to-ttg44-chassislo shadow-[0_24px_50px_-26px_oklch(0_0_0/0.9),inset_0_1px_0_oklch(1_0_0/0.09)] has-checked:[&_.ttg44-state]:text-ttg44-paint">
    <span class="flex flex-col gap-0.5">
      <b class="text-[15.5px] font-semibold text-ttg44-ink">Ringer</b>
      <span class="ttg44-state text-[12.5px] text-ttg44-mute transition-colors duration-200">Slide down to silence</span>
    </span>
    <span class="relative shrink-0 w-[74px] h-11 rounded-[13px] overflow-hidden bg-ttg44-channel shadow-[inset_0_2px_5px_oklch(0_0_0/0.75),inset_0_0_0_1px_oklch(0_0_0/0.5)]">
      <span aria-hidden="true" class="absolute inset-y-1.5 left-1.5 w-8 rounded-lg bg-ttg44-paint shadow-[inset_0_1px_2px_oklch(0_0_0/0.35)]"></span>
      <input type="checkbox" id="ttg-44-sw" role="switch" aria-label="Silent mode" class="peer appearance-none absolute inset-0 w-full h-full bg-transparent cursor-pointer z-20 focus-visible:outline-3 focus-visible:outline-ttg44-focus focus-visible:outline-offset-4">
      <span aria-hidden="true" class="ttg44-grip pointer-events-none absolute top-1 left-1 z-10 w-9 h-9 rounded-[10px] bg-linear-to-b from-ttg44-griphi to-ttg44-griplo shadow-[0_2px_5px_oklch(0_0_0/0.6),inset_0_1px_0_oklch(1_0_0/0.45)] transition-transform duration-150 ease-out peer-checked:translate-x-[30px] motion-reduce:transition-none">
        <i class="absolute inset-y-2 inset-x-1.5 rounded-sm opacity-70 [background:repeating-linear-gradient(90deg,var(--color-ttg44-ridgehi)_0_1px,var(--color-ttg44-ridgelo)_1px_3px)]"></i>
      </span>
    </span>
  </label>
  <p class="text-[11px] tracking-[0.16em] uppercase text-ttg44-mute">Orange showing = silent</p>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-ttg44-bg: #1b1d21;
  --color-ttg44-bg: oklch(0.23 0.005 265);
  --color-ttg44-chassishi: #3a3e45;
  --color-ttg44-chassishi: oklch(0.36 0.007 265);
  --color-ttg44-chassislo: #2b2e34;
  --color-ttg44-chassislo: oklch(0.3 0.006 265);
  --color-ttg44-channel: #17191d;
  --color-ttg44-channel: oklch(0.2 0.005 265);
  --color-ttg44-paint: #f07a2a;
  --color-ttg44-paint: oklch(0.7 0.18 50);
  --color-ttg44-griphi: #e6e9ef;
  --color-ttg44-griphi: oklch(0.93 0.006 265);
  --color-ttg44-griplo: #b7bcc6;
  --color-ttg44-griplo: oklch(0.79 0.008 265);
  --color-ttg44-ridgehi: #ffffff;
  --color-ttg44-ridgehi: oklch(1 0 0 / 0.75);
  --color-ttg44-ridgelo: #8d929c;
  --color-ttg44-ridgelo: oklch(0.65 0.01 265 / 0.6);
  --color-ttg44-ink: #e4e7ee;
  --color-ttg44-ink: oklch(0.92 0.006 265);
  --color-ttg44-mute: #949aa6;
  --color-ttg44-mute: oklch(0.68 0.012 265);
  --color-ttg44-focus: #6cb6f0;
  --color-ttg44-focus: oklch(0.74 0.14 235);
  --font-ttg44-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}

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

.ttg-44 input[type="checkbox"] {
  -webkit-appearance: none;
}
```

How this works

Nothing changes colour; something is revealed. The orange band is always there, painted on the floor of the channel. Sliding the grip uncovers it. That inversion is the whole reason this reads as hardware — real switches do not repaint themselves.

Knurling is a repeating gradient. Six or seven hard stops across 6px, plus a vertical light gradient over the top, and the grip has a machined surface for the cost of one declaration.

Travel is short and fast. 150ms with no overshoot: a slider in a channel has friction and a hard stop, and an elastic curve here would immediately read as software.

Make it yours

  • Reveal colour through --color-ttg44-paint — orange is the convention for mute, but red works for power.
  • Finer knurl: halve the repeat interval; coarser: double it.
  • Vertical slider: swap the axis and rotate the knurl gradient to 0deg.
  • Add an engraved legend beside the channel using the text-shadow pair from demo 26.

Gotchas — read before shipping

  • The reveal band must be inside the channel's overflow-hidden box, or it shows at the ends when the grip is centred.
  • Do not use a bouncy curve. Physical sliders stop dead; overshoot makes the metaphor collapse.
  • Colour alone is the state here, so the demo pairs it with grip POSITION and a text readout — an orange band is meaningless to a user who cannot see it.
  • Keep the grip at least 44px tall even if the channel is slim; the housing can be smaller than the target.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

Repeating gradients, transforms and inset shadows only — universally supported in modern browsers.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Arbitraryneeds bracket syntax

Search CodeFronts

Loading…