02 / 47
All 47 in 47 Tailwind CSS Toggles & Switches
- 01Tailwind iOS-Style Toggle Switch with appearance-none
- 02Tailwind Dark Mode Sun / Moon Theme Switcher
- 03Tailwind Neumorphic Soft-UI Pill Toggle
- 04Tailwind Gooey Liquid Morphing Switch with SVG Filter
- 05Tailwind Bouncy Elastic Physics Toggle (Overshoot Cubic-Bezier)
- 06Tailwind ON / OFF Text Switch with Labels Inside the Track
- 07Tailwind SaaS Pricing Toggle — Monthly / Annually Segmented Pill
- 08Tailwind Mechanical Keycap Toggles with Haptic Feedback
- 09Tailwind Waveform Mute Toggle with Animated EQ Bars
- 10Tailwind Timed Auto-Off Toggle with Conic Countdown Ring
- 11Tailwind Press-and-Hold to Confirm Toggle (Fingerprint Scan)
- 12Tailwind Split-Flap Departure Board Toggle (3D Flip)
- 13Tailwind Permission Toggle Group with :has() Live Status Badge
- 14Tailwind Material Design 3 Switch with State Layer
- 15Tailwind Skeuomorphic Wall Light Switch with Room Relight
- 16Tailwind Neon Cyberpunk Toggle with Clipped Corners
- 17Tailwind Brutalist Snap Toggle with Hard Offset Shadow
- 18Tailwind Day / Night Landscape Scene Switch
- 19Tailwind 3D Flip Card Toggle (rotateY Switch)
- 20Tailwind Sliding Pill Toggle with Label Inside the Thumb
- 21Tailwind Glassmorphism Frosted Toggle with backdrop-blur
- 22Tailwind Rotary Knob Toggle with Brushed-Metal Conic Gradient
- 23Tailwind iOS Settings List with Grouped Toggle Rows
- 24Tailwind Minimal Outline Toggle Drawn in currentColor
- 25Tailwind Squash-and-Stretch Pebble Toggle
- 26Tailwind Industrial Rocker I/O Power Switch
- 27Tailwind Accessible role=switch Toggle with forced-colors Support
- 28Tailwind Macro-Pad Toggle Grid with RGB Underglow
- 29Tailwind Radial VU Meter Mute Toggle
- 30Tailwind Segmented Pip Countdown Auto-Off Toggle
- 31Tailwind Slide-to-Confirm Toggle Rail (Drag or Arrow Keys)
- 32Tailwind Odometer Roll ON / OFF Toggle
- 33Tailwind Master Toggle with Indeterminate Tri-State
- 34Tailwind iOS Control Centre Tile Toggles
- 35Tailwind Material 3 Connected Icon Toggle Buttons
- 36Tailwind Two-Gang Wall Plate with Cumulative Room Light
- 37Tailwind Neon Toggle with Animated Conic Border Light
- 38Tailwind Brutalist Rubber-Stamp Toggle
- 39Tailwind Aurora Night Sky Toggle Switch
- 40Tailwind 3D Rotating Cube Toggle
- 41Tailwind Three-Position Off / Auto / On Selector
- 42Tailwind Liquid Glass Toggle with Specular Highlight
- 43Tailwind Three-Detent Rotary Selector Knob
- 44Tailwind Hardware Slide Switch with Knurled Grip
- 45Tailwind Battery Saver Toggle with Live Fill Meter
- 46Tailwind Morphing Sun-to-Moon Icon Toggle (SVG Stroke)
- 47Tailwind Guarded Kill Switch Under a Flip-Up Safety Cover
Tailwind Dark Mode Sun / Moon Theme Switcher
The day/night switch, ported whole: the thumb is a glowing sun that morphs into a crescent via a single inset box-shadow transition, stars fade in, a cloud drifts out — and the surrounding panel re-themes itself through has-checked:, the utility form of :has(:checked).
Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time
Untitled UI React · Affiliate link
The code
<section class="ttg-02 w-full min-h-svh flex flex-col items-center justify-center gap-7 px-5 py-14 bg-ttg02-daybg text-ttg02-dayink font-ttg02-sans transition-colors duration-500 has-checked:bg-ttg02-nightbg has-checked:text-ttg02-nightink" aria-label="Dark mode sun and moon theme switcher">
<label for="ttg-02-sw" class="flex items-center gap-7 min-h-14 px-6 py-4 rounded-2xl cursor-pointer transition-colors duration-500 bg-white/60 has-checked:bg-white/5 shadow-[0_1px_2px_oklch(0.4_0.05_250/0.08)]">
<span class="flex flex-col gap-0.5">
<span class="text-[15.5px] font-semibold">Appearance</span>
<span class="text-[12.5px] opacity-60">Follows this switch, not the system</span>
</span>
<span class="relative inline-block shrink-0">
<input type="checkbox" id="ttg-02-sw" role="switch" class="peer appearance-none block w-[74px] h-9 rounded-full cursor-pointer relative bg-ttg02-day bg-linear-to-b from-ttg02-day to-ttg02-dayhi transition-[background-color,background-image] duration-[450ms] shadow-[inset_0_2px_5px_oklch(0.35_0.09_250/0.3)] checked:from-ttg02-night checked:to-ttg02-nighthi before:content-[''] before:absolute before:top-1 before:left-1 before:w-7 before:h-7 before:rounded-full before:z-10 before:shadow-[inset_0_0_0_14px_#ffd54f,0_0_12px_oklch(0.85_0.17_85/0.75)] before:transition-[transform,box-shadow] before:duration-[450ms] before:ease-[cubic-bezier(0.3,1.2,0.4,1)] checked:before:translate-x-[38px] checked:before:shadow-[inset_-8px_-4px_0_1px_#f4f1de,0_0_10px_oklch(0.9_0.03_270/0.45)] focus-visible:outline-3 focus-visible:outline-ttg02-focus focus-visible:outline-offset-3 motion-reduce:transition-none motion-reduce:before:transition-none">
<span aria-hidden="true" class="pointer-events-none absolute top-[9px] left-3 w-0.5 h-0.5 rounded-full bg-white opacity-0 transition-opacity duration-[450ms] shadow-[10px_4px_0_#fff,4px_14px_0_0_#dfe8ff,16px_16px_0_#fff,26px_7px_0_0_#dfe8ff] peer-checked:opacity-95 motion-reduce:transition-none"></span>
<span aria-hidden="true" class="pointer-events-none absolute top-[19px] right-3 w-[18px] h-[7px] rounded-lg bg-white opacity-95 transition-[opacity,transform] duration-[450ms] shadow-[-7px_-4px_0_-1px_#fff,6px_-3px_0_-2px_#fff] peer-checked:opacity-0 peer-checked:translate-x-2 motion-reduce:transition-none"></span>
</span>
</label>
<p class="font-ttg02-mono text-[11px] tracking-[0.14em] uppercase opacity-55">Sun ↔ moon · pure Tailwind morph</p>
</section><section class="ttg-02 w-full min-h-svh flex flex-col items-center justify-center gap-7 px-5 py-14 bg-ttg02-daybg text-ttg02-dayink font-ttg02-sans transition-colors duration-500 has-checked:bg-ttg02-nightbg has-checked:text-ttg02-nightink" aria-label="Dark mode sun and moon theme switcher">
<label for="ttg-02-sw" class="flex items-center gap-7 min-h-14 px-6 py-4 rounded-2xl cursor-pointer transition-colors duration-500 bg-white/60 has-checked:bg-white/5 shadow-[0_1px_2px_oklch(0.4_0.05_250/0.08)]">
<span class="flex flex-col gap-0.5">
<span class="text-[15.5px] font-semibold">Appearance</span>
<span class="text-[12.5px] opacity-60">Follows this switch, not the system</span>
</span>
<span class="relative inline-block shrink-0">
<input type="checkbox" id="ttg-02-sw" role="switch" class="peer appearance-none block w-[74px] h-9 rounded-full cursor-pointer relative bg-ttg02-day bg-linear-to-b from-ttg02-day to-ttg02-dayhi transition-[background-color,background-image] duration-[450ms] shadow-[inset_0_2px_5px_oklch(0.35_0.09_250/0.3)] checked:from-ttg02-night checked:to-ttg02-nighthi before:content-[''] before:absolute before:top-1 before:left-1 before:w-7 before:h-7 before:rounded-full before:z-10 before:shadow-[inset_0_0_0_14px_#ffd54f,0_0_12px_oklch(0.85_0.17_85/0.75)] before:transition-[transform,box-shadow] before:duration-[450ms] before:ease-[cubic-bezier(0.3,1.2,0.4,1)] checked:before:translate-x-[38px] checked:before:shadow-[inset_-8px_-4px_0_1px_#f4f1de,0_0_10px_oklch(0.9_0.03_270/0.45)] focus-visible:outline-3 focus-visible:outline-ttg02-focus focus-visible:outline-offset-3 motion-reduce:transition-none motion-reduce:before:transition-none">
<span aria-hidden="true" class="pointer-events-none absolute top-[9px] left-3 w-0.5 h-0.5 rounded-full bg-white opacity-0 transition-opacity duration-[450ms] shadow-[10px_4px_0_#fff,4px_14px_0_0_#dfe8ff,16px_16px_0_#fff,26px_7px_0_0_#dfe8ff] peer-checked:opacity-95 motion-reduce:transition-none"></span>
<span aria-hidden="true" class="pointer-events-none absolute top-[19px] right-3 w-[18px] h-[7px] rounded-lg bg-white opacity-95 transition-[opacity,transform] duration-[450ms] shadow-[-7px_-4px_0_-1px_#fff,6px_-3px_0_-2px_#fff] peer-checked:opacity-0 peer-checked:translate-x-2 motion-reduce:transition-none"></span>
</span>
</label>
<p class="font-ttg02-mono text-[11px] tracking-[0.14em] uppercase opacity-55">Sun ↔ moon · pure Tailwind morph</p>
</section>@import "tailwindcss";
@theme {
--color-ttg02-day: #7ecbf5;
--color-ttg02-day: oklch(0.8 0.1 235);
--color-ttg02-dayhi: #b3e0f9;
--color-ttg02-dayhi: oklch(0.88 0.06 235);
--color-ttg02-night: #1c2a4a;
--color-ttg02-night: oklch(0.3 0.06 265);
--color-ttg02-nighthi: #0f1830;
--color-ttg02-nighthi: oklch(0.22 0.05 265);
--color-ttg02-daybg: #e7f2fb;
--color-ttg02-daybg: oklch(0.95 0.02 235);
--color-ttg02-dayink: #1f2936;
--color-ttg02-dayink: oklch(0.29 0.02 250);
--color-ttg02-nightbg: #0b1220;
--color-ttg02-nightbg: oklch(0.18 0.03 265);
--color-ttg02-nightink: #d5dcec;
--color-ttg02-nightink: oklch(0.88 0.02 265);
--color-ttg02-focus: #4d9fff;
--color-ttg02-focus: oklch(0.7 0.16 250);
--font-ttg02-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
--font-ttg02-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.ttg-02 {
width: 100%;
min-height: 100svh;
}
.ttg-02 input[type="checkbox"] {
-webkit-appearance: none;
}@import "tailwindcss";
@theme {
--color-ttg02-day: #7ecbf5;
--color-ttg02-day: oklch(0.8 0.1 235);
--color-ttg02-dayhi: #b3e0f9;
--color-ttg02-dayhi: oklch(0.88 0.06 235);
--color-ttg02-night: #1c2a4a;
--color-ttg02-night: oklch(0.3 0.06 265);
--color-ttg02-nighthi: #0f1830;
--color-ttg02-nighthi: oklch(0.22 0.05 265);
--color-ttg02-daybg: #e7f2fb;
--color-ttg02-daybg: oklch(0.95 0.02 235);
--color-ttg02-dayink: #1f2936;
--color-ttg02-dayink: oklch(0.29 0.02 250);
--color-ttg02-nightbg: #0b1220;
--color-ttg02-nightbg: oklch(0.18 0.03 265);
--color-ttg02-nightink: #d5dcec;
--color-ttg02-nightink: oklch(0.88 0.02 265);
--color-ttg02-focus: #4d9fff;
--color-ttg02-focus: oklch(0.7 0.16 250);
--font-ttg02-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
--font-ttg02-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.ttg-02 {
width: 100%;
min-height: 100svh;
}
.ttg-02 input[type="checkbox"] {
-webkit-appearance: none;
}Setup — do this once per project
Skip this if your project already runs Tailwind v4.
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<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.
npm install tailwindcss @tailwindcss/vite
npm install tailwindcss @tailwindcss/vite// vite.config.js ("type": "module" in package.json)
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [tailwindcss()],
})// vite.config.js ("type": "module" in package.json)
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [tailwindcss()],
})Any v4 setup works — Vite, PostCSS or the CLI. Nothing in this demo is bundler-specific.
@import "tailwindcss";
@theme {
--color-ttg02-day: #7ecbf5;
--color-ttg02-day: oklch(0.8 0.1 235);
--color-ttg02-dayhi: #b3e0f9;
--color-ttg02-dayhi: oklch(0.88 0.06 235);
--color-ttg02-night: #1c2a4a;
--color-ttg02-night: oklch(0.3 0.06 265);
--color-ttg02-nighthi: #0f1830;
--color-ttg02-nighthi: oklch(0.22 0.05 265);
--color-ttg02-daybg: #e7f2fb;
--color-ttg02-daybg: oklch(0.95 0.02 235);
--color-ttg02-dayink: #1f2936;
--color-ttg02-dayink: oklch(0.29 0.02 250);
--color-ttg02-nightbg: #0b1220;
--color-ttg02-nightbg: oklch(0.18 0.03 265);
--color-ttg02-nightink: #d5dcec;
--color-ttg02-nightink: oklch(0.88 0.02 265);
--color-ttg02-focus: #4d9fff;
--color-ttg02-focus: oklch(0.7 0.16 250);
--font-ttg02-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
--font-ttg02-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.ttg-02 {
width: 100%;
min-height: 100svh;
}
.ttg-02 input[type="checkbox"] {
-webkit-appearance: none;
}@import "tailwindcss";
@theme {
--color-ttg02-day: #7ecbf5;
--color-ttg02-day: oklch(0.8 0.1 235);
--color-ttg02-dayhi: #b3e0f9;
--color-ttg02-dayhi: oklch(0.88 0.06 235);
--color-ttg02-night: #1c2a4a;
--color-ttg02-night: oklch(0.3 0.06 265);
--color-ttg02-nighthi: #0f1830;
--color-ttg02-nighthi: oklch(0.22 0.05 265);
--color-ttg02-daybg: #e7f2fb;
--color-ttg02-daybg: oklch(0.95 0.02 235);
--color-ttg02-dayink: #1f2936;
--color-ttg02-dayink: oklch(0.29 0.02 250);
--color-ttg02-nightbg: #0b1220;
--color-ttg02-nightbg: oklch(0.18 0.03 265);
--color-ttg02-nightink: #d5dcec;
--color-ttg02-nightink: oklch(0.88 0.02 265);
--color-ttg02-focus: #4d9fff;
--color-ttg02-focus: oklch(0.7 0.16 250);
--font-ttg02-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
--font-ttg02-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.ttg-02 {
width: 100%;
min-height: 100svh;
}
.ttg-02 input[type="checkbox"] {
-webkit-appearance: none;
}<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">
<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.
- Two relationships, two variants:
peer-checked:for the star field and cloud (siblings),has-checked:for the section and the label card (ancestors). The CSS original needed a~rule and a separate:has()rule; each element now declares its own reaction. - The sky gradient became
bg-linear-to-b from-* to-*withchecked:from-* checked:to-*, which is strictly better than the original'sbackground-colortransition — both stops now animate rather than just the base colour. - The four-star field stays an arbitrary
shadow-[...]: it is a drawing, not a design-scale value, and promoting it to@themewould mint utilities nobody would reuse. - UI change from the CSS original: the switch gained a translucent card that re-themes with the panel, the label gained a second line so the control explains itself, and the night background moved from
#0d1526tooklch(0.18 0.03 265), lifting body text to 11:1 (it was 8.4:1).
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 Dark Mode Sun / Moon Theme Switcher
Source: https://codefronts.com/components/tailwind-css-toggles-switches/tailwind-dark-mode-sun-moon-theme-switcher/
The day/night switch, ported whole: the thumb is a glowing sun that morphs into a crescent via a single inset box-shadow transition, stars fade in, a cloud drifts out — and the surrounding panel re-themes itself through has-checked:, the utility form of :has(:checked).
## HTML
```html
<section class="ttg-02 w-full min-h-svh flex flex-col items-center justify-center gap-7 px-5 py-14 bg-ttg02-daybg text-ttg02-dayink font-ttg02-sans transition-colors duration-500 has-checked:bg-ttg02-nightbg has-checked:text-ttg02-nightink" aria-label="Dark mode sun and moon theme switcher">
<label for="ttg-02-sw" class="flex items-center gap-7 min-h-14 px-6 py-4 rounded-2xl cursor-pointer transition-colors duration-500 bg-white/60 has-checked:bg-white/5 shadow-[0_1px_2px_oklch(0.4_0.05_250/0.08)]">
<span class="flex flex-col gap-0.5">
<span class="text-[15.5px] font-semibold">Appearance</span>
<span class="text-[12.5px] opacity-60">Follows this switch, not the system</span>
</span>
<span class="relative inline-block shrink-0">
<input type="checkbox" id="ttg-02-sw" role="switch" class="peer appearance-none block w-[74px] h-9 rounded-full cursor-pointer relative bg-ttg02-day bg-linear-to-b from-ttg02-day to-ttg02-dayhi transition-[background-color,background-image] duration-[450ms] shadow-[inset_0_2px_5px_oklch(0.35_0.09_250/0.3)] checked:from-ttg02-night checked:to-ttg02-nighthi before:content-[''] before:absolute before:top-1 before:left-1 before:w-7 before:h-7 before:rounded-full before:z-10 before:shadow-[inset_0_0_0_14px_#ffd54f,0_0_12px_oklch(0.85_0.17_85/0.75)] before:transition-[transform,box-shadow] before:duration-[450ms] before:ease-[cubic-bezier(0.3,1.2,0.4,1)] checked:before:translate-x-[38px] checked:before:shadow-[inset_-8px_-4px_0_1px_#f4f1de,0_0_10px_oklch(0.9_0.03_270/0.45)] focus-visible:outline-3 focus-visible:outline-ttg02-focus focus-visible:outline-offset-3 motion-reduce:transition-none motion-reduce:before:transition-none">
<span aria-hidden="true" class="pointer-events-none absolute top-[9px] left-3 w-0.5 h-0.5 rounded-full bg-white opacity-0 transition-opacity duration-[450ms] shadow-[10px_4px_0_#fff,4px_14px_0_0_#dfe8ff,16px_16px_0_#fff,26px_7px_0_0_#dfe8ff] peer-checked:opacity-95 motion-reduce:transition-none"></span>
<span aria-hidden="true" class="pointer-events-none absolute top-[19px] right-3 w-[18px] h-[7px] rounded-lg bg-white opacity-95 transition-[opacity,transform] duration-[450ms] shadow-[-7px_-4px_0_-1px_#fff,6px_-3px_0_-2px_#fff] peer-checked:opacity-0 peer-checked:translate-x-2 motion-reduce:transition-none"></span>
</span>
</label>
<p class="font-ttg02-mono text-[11px] tracking-[0.14em] uppercase opacity-55">Sun ↔ moon · pure Tailwind morph</p>
</section>
```
## CSS
```css
@import "tailwindcss";
@theme {
--color-ttg02-day: #7ecbf5;
--color-ttg02-day: oklch(0.8 0.1 235);
--color-ttg02-dayhi: #b3e0f9;
--color-ttg02-dayhi: oklch(0.88 0.06 235);
--color-ttg02-night: #1c2a4a;
--color-ttg02-night: oklch(0.3 0.06 265);
--color-ttg02-nighthi: #0f1830;
--color-ttg02-nighthi: oklch(0.22 0.05 265);
--color-ttg02-daybg: #e7f2fb;
--color-ttg02-daybg: oklch(0.95 0.02 235);
--color-ttg02-dayink: #1f2936;
--color-ttg02-dayink: oklch(0.29 0.02 250);
--color-ttg02-nightbg: #0b1220;
--color-ttg02-nightbg: oklch(0.18 0.03 265);
--color-ttg02-nightink: #d5dcec;
--color-ttg02-nightink: oklch(0.88 0.02 265);
--color-ttg02-focus: #4d9fff;
--color-ttg02-focus: oklch(0.7 0.16 250);
--font-ttg02-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
--font-ttg02-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.ttg-02 {
width: 100%;
min-height: 100svh;
}
.ttg-02 input[type="checkbox"] {
-webkit-appearance: none;
}
```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 Dark Mode Sun / Moon Theme Switcher
Source: https://codefronts.com/components/tailwind-css-toggles-switches/tailwind-dark-mode-sun-moon-theme-switcher/
The day/night switch, ported whole: the thumb is a glowing sun that morphs into a crescent via a single inset box-shadow transition, stars fade in, a cloud drifts out — and the surrounding panel re-themes itself through has-checked:, the utility form of :has(:checked).
## HTML
```html
<section class="ttg-02 w-full min-h-svh flex flex-col items-center justify-center gap-7 px-5 py-14 bg-ttg02-daybg text-ttg02-dayink font-ttg02-sans transition-colors duration-500 has-checked:bg-ttg02-nightbg has-checked:text-ttg02-nightink" aria-label="Dark mode sun and moon theme switcher">
<label for="ttg-02-sw" class="flex items-center gap-7 min-h-14 px-6 py-4 rounded-2xl cursor-pointer transition-colors duration-500 bg-white/60 has-checked:bg-white/5 shadow-[0_1px_2px_oklch(0.4_0.05_250/0.08)]">
<span class="flex flex-col gap-0.5">
<span class="text-[15.5px] font-semibold">Appearance</span>
<span class="text-[12.5px] opacity-60">Follows this switch, not the system</span>
</span>
<span class="relative inline-block shrink-0">
<input type="checkbox" id="ttg-02-sw" role="switch" class="peer appearance-none block w-[74px] h-9 rounded-full cursor-pointer relative bg-ttg02-day bg-linear-to-b from-ttg02-day to-ttg02-dayhi transition-[background-color,background-image] duration-[450ms] shadow-[inset_0_2px_5px_oklch(0.35_0.09_250/0.3)] checked:from-ttg02-night checked:to-ttg02-nighthi before:content-[''] before:absolute before:top-1 before:left-1 before:w-7 before:h-7 before:rounded-full before:z-10 before:shadow-[inset_0_0_0_14px_#ffd54f,0_0_12px_oklch(0.85_0.17_85/0.75)] before:transition-[transform,box-shadow] before:duration-[450ms] before:ease-[cubic-bezier(0.3,1.2,0.4,1)] checked:before:translate-x-[38px] checked:before:shadow-[inset_-8px_-4px_0_1px_#f4f1de,0_0_10px_oklch(0.9_0.03_270/0.45)] focus-visible:outline-3 focus-visible:outline-ttg02-focus focus-visible:outline-offset-3 motion-reduce:transition-none motion-reduce:before:transition-none">
<span aria-hidden="true" class="pointer-events-none absolute top-[9px] left-3 w-0.5 h-0.5 rounded-full bg-white opacity-0 transition-opacity duration-[450ms] shadow-[10px_4px_0_#fff,4px_14px_0_0_#dfe8ff,16px_16px_0_#fff,26px_7px_0_0_#dfe8ff] peer-checked:opacity-95 motion-reduce:transition-none"></span>
<span aria-hidden="true" class="pointer-events-none absolute top-[19px] right-3 w-[18px] h-[7px] rounded-lg bg-white opacity-95 transition-[opacity,transform] duration-[450ms] shadow-[-7px_-4px_0_-1px_#fff,6px_-3px_0_-2px_#fff] peer-checked:opacity-0 peer-checked:translate-x-2 motion-reduce:transition-none"></span>
</span>
</label>
<p class="font-ttg02-mono text-[11px] tracking-[0.14em] uppercase opacity-55">Sun ↔ moon · pure Tailwind morph</p>
</section>
```
## CSS
```css
@import "tailwindcss";
@theme {
--color-ttg02-day: #7ecbf5;
--color-ttg02-day: oklch(0.8 0.1 235);
--color-ttg02-dayhi: #b3e0f9;
--color-ttg02-dayhi: oklch(0.88 0.06 235);
--color-ttg02-night: #1c2a4a;
--color-ttg02-night: oklch(0.3 0.06 265);
--color-ttg02-nighthi: #0f1830;
--color-ttg02-nighthi: oklch(0.22 0.05 265);
--color-ttg02-daybg: #e7f2fb;
--color-ttg02-daybg: oklch(0.95 0.02 235);
--color-ttg02-dayink: #1f2936;
--color-ttg02-dayink: oklch(0.29 0.02 250);
--color-ttg02-nightbg: #0b1220;
--color-ttg02-nightbg: oklch(0.18 0.03 265);
--color-ttg02-nightink: #d5dcec;
--color-ttg02-nightink: oklch(0.88 0.02 265);
--color-ttg02-focus: #4d9fff;
--color-ttg02-focus: oklch(0.7 0.16 250);
--font-ttg02-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
--font-ttg02-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.ttg-02 {
width: 100%;
min-height: 100svh;
}
.ttg-02 input[type="checkbox"] {
-webkit-appearance: none;
}
```How this works
The crescent is one transition, not two elements. Unchecked, the thumb carries shadow-[inset_0_0_0_14px_#ffd54f,0_0_12px_oklch(0.85_0.17_85/0.8)] — a 14px inset ring on a 28px circle fills it solid, so it reads as a sun. Checked, that becomes inset -8px -4px 0 1px: only a crescent-shaped sliver is painted. Because inset shadows clip to the border radius, the moon can never bleed past the thumb or mismatch the sky.
Two relationships, two variants. The stars and cloud are siblings of the input, so they use peer-checked:. The section is an ancestor, so it uses has-checked:. The CSS version needed a sibling combinator and a :has() rule in two different places; here each element states its own reaction.
Decorations stay out of the accessibility tree. Both spans carry aria-hidden="true"; only the input is announced, as a switch.
Make it yours
- Retheme through
--color-ttg02-day/--color-ttg02-night— sky, glow and panel all read them. - Add stars by appending offsets to the
shadow-[...]list on the star span. - Hook a real theme: move
has-checked:to the<html>element and swap tokens there instead of colours here. - Slow the celestial swap by raising both
duration-[450ms]values together.
Gotchas — read before shipping
- Draw the crescent with an INSET shadow, never an overlay circle — an overlay has to match the sky colour exactly and breaks the moment the track gradient changes.
peeronly reaches later siblings. The star field and cloud must come AFTER the input in source order, exactly as they do here.- Crossfade with
opacity, nothidden— adisplaychange cannot transition and forces layout.
Browser support
| Chrome | Safari | Firefox | Edge |
|---|---|---|---|
| 111+ | 16.4+ | 128+ | 111+ |
has-checked: compiles to :has(:checked) (Firefox 121+); without it the switch still morphs perfectly and only the panel retheme is lost.