What is the CSS Dark Mode Generator?
Generate dark mode CSS using prefers-color-scheme, data-theme attributes, or CSS custom properties. Three implementation strategies in one tool.
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 Dark Mode 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.
Choose strategy
OS preference only: follows the OS setting. Toggle + OS: lets users override the OS setting. Class toggle: legacy approach for maximum compatibility.
Set your colour pairs
Enter light and dark values for background, surface, text, secondary text, border, and primary colour.
Copy the CSS and optional JS
Strategy 2 requires a small JavaScript snippet to toggle the data-theme attribute. It is included in the output.
What the generated code looks like
Clean, production-ready CSS — no vendor bloat, no unnecessary declarations.
/* Strategy 1: OS preference only (simplest) */
@media (prefers-color-scheme: dark) {
:root {
--bg: #000;
--text: #f5f5f7;
}
}
/* Strategy 2: Toggle + OS fallback (recommended) */
:root { --bg: #fff; --text: #1d1d1f; }
[data-theme="dark"] { --bg: #000; --text: #f5f5f7; }
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--bg: #000; --text: #f5f5f7;
}
}
/* Strategy 3: Class toggle (legacy) */
.dark-mode body { background: #000; color: #f5f5f7; }Pro tips for better results
Always test dark mode for contrast ratios
Dark backgrounds with coloured text often fail WCAG AA contrast (4.5:1). Light text on dark backgrounds can also be hard to read at full saturation. Use a contrast checker after generating your dark palette.
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.