Return_to_vault
[CONSTRUCT: 2026-02-12]
Tailwind Dark Theme Toggle
CSSTailwindDesign System
Tailwind Dark Theme Toggle
CSS custom properties for dark/light theme switching that plays nice with Tailwind. Light mode lives in :root, dark mode overrides live under .dark. The gold accent (43 33% 51%) only shows up in dark mode because the brand is dark-first. Light mode gets a standard blue primary instead.
When to Use
- Building a site that supports both light and dark themes with Tailwind
- You want your design tokens in one place instead of scattered across utility classes
- Dark-mode-first projects where the dark palette is the primary brand identity
The Code
/* Light mode defaults */
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--primary: 221 83% 53%;
--primary-foreground: 0 0% 98%;
--secondary: 240 4.8% 95.9%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--border: 240 5.9% 90%;
--ring: 221 83% 53%;
--radius: 0.5rem;
}
/* Dark mode overrides */
.dark {
--background: 240 10% 3.9%; /* Zinc-950 */
--foreground: 0 0% 98%;
--primary: 43 33% 51%; /* Gold #ae9558 */
--primary-foreground: 0 0% 100%;
--secondary: 240 3.7% 15.9%; /* Zinc-800 */
--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;
--border: 240 3.7% 15.9%;
--ring: 43 33% 51%;
}
/* Usage in Tailwind: bg-background, text-foreground, etc. */
/* tailwind.config.ts maps these to hsl(var(--token)) */
Notes
The HSL values are stored without the hsl() wrapper so Tailwind can compose them with opacity modifiers. Your tailwind.config.ts maps each token as hsl(var(--token)), which lets you write bg-primary/80 for 80% opacity without any extra config.