What is the CSS Theme Generator?
Generate a light and dark mode CSS theme using custom properties. One toggle to switch between themes without page reload.
Everything runs locally in your browser. Adjust the controls above, preview instantly, and copy clean, production-ready CSS — no account, no upload.
Using the CSS Theme Generator
Everything lives in the panel at the top of this page. There is nothing to install — it all runs right here in your browser.
Set your light theme colours
Enter background, surface, text, secondary text, border, and primary colours for the light mode.
Configure dark equivalents
The generator suggests dark mode equivalents by inverting lightness values. Adjust the suggestions to match your design.
Copy both :root and [data-theme] blocks
Paste into your global CSS. Add data-theme="dark" to the HTML element to activate dark mode.
What the generated code looks like
Clean, production-ready CSS — no vendor bloat, no unnecessary declarations.
:root {
--bg: #ffffff;
--bg-surface: #f5f5f7;
--text: #1d1d1f;
--text-secondary: #86868b;
--border: #e5e7eb;
--primary: #0071e3;
}
[data-theme="dark"] {
--bg: #000000;
--bg-surface: #1c1c1e;
--text: #f5f5f7;
--text-secondary: #98989d;
--border: #38383a;
--primary: #2997ff;
}Switching themes is a single JavaScript line: document.documentElement.setAttribute("data-theme", "dark"). No CSS class toggling, no style recalculation beyond the custom property cascade.
Pro tips for better results
Respect the OS preference with prefers-color-scheme
Add @media (prefers-color-scheme: dark) { :root { /* dark values */ } } as the default for users who have not toggled manually. Override with [data-theme] when the user makes a choice.
Persist theme preference in localStorage
Store the user's theme choice: localStorage.setItem("theme", "dark"). Read it on page load before first render to prevent a flash of the wrong theme.
Frequently asked questions
From the blog
Read more →The Complete Guide to CSS Gradients (2026)
Master linear, radial, and conic CSS gradients. Learn color stops, angles, hard stops for stripes, multi-layer gradients, and the tricks behind smooth, professional results.
How to Create Glassmorphism in CSS: The Complete 2026 Guide
Learn how to build the frosted-glass effect with CSS backdrop-filter. Real code, the accessibility traps nobody mentions, browser support, and performance tips from production.
CSS clamp() and Fluid Typography: Stop Writing Font-Size Media Queries (2026)
Learn how CSS clamp() creates type that scales smoothly between screen sizes with a single line, the formula behind it, and how to build a fully fluid type scale without media queries.