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 →Modern CSS techniques every developer should know
A practical tour of the CSS features that replaced yesterday’s hacks.
From design to code without the friction
How visual generators speed up the build without sacrificing clean output.
Writing CSS that scales with your project
Tokens, naming, and structure that keep large stylesheets maintainable.