CSS Variable Theme Builder - Online Light & Dark Mode
Define a set of colors for light and dark themes. Get the CSS custom properties snippet. Toggle live.
UD5 Toolkit
/* Detect system color scheme */ @media (prefers-color-scheme: dark) { body { background-color: #1a1a2e; color: #e0e0e0; } } @media (prefers-color-scheme: light) { body { background-color: #ffffff; color: #1a1d23; } }
/* Tell browser which scheme to use */ :root { color-scheme: light dark; } .dark-theme { color-scheme: dark; --bg: #1e1e2e; --text: #e0e0e0; --surface: #2d2d3f; }
prefers-color-scheme?
prefers-color-scheme is a CSS media feature that detects whether the user has requested a light or dark color theme at the operating system level. It allows websites to automatically adapt their appearance to match the user's system preference, providing a seamless and comfortable viewing experience. The possible values are light, dark, and no-preference.
prefers-color-scheme?
prefers-color-scheme is widely supported across all modern browsers: Chrome 76+, Firefox 67+, Safari 12.1+, Edge 79+, and Opera 62+. It also works on mobile browsers including iOS Safari 13+ and Chrome for Android. Global browser support exceeds 97% as of 2025, making it safe for production use.
color-scheme and prefers-color-scheme?
prefers-color-scheme is a media query that detects the user's OS-level preference (read-only). color-scheme is a CSS property that tells the browser which color scheme an element should render with. Setting color-scheme: dark on an element makes native UI controls (inputs, selects, scrollbars, buttons) render in their dark variant. They work best together: use prefers-color-scheme to detect preference, and color-scheme to inform the browser how to render form elements.
Use window.matchMedia('(prefers-color-scheme: dark)') in JavaScript. This returns a MediaQueryList object with a matches boolean property. You can also listen for real-time changes using addEventListener('change', callback), which fires whenever the user toggles their system theme. This enables dynamic, instant theme switching without page reload.
This is often because the color-scheme CSS property hasn't been set. While prefers-color-scheme detects the system setting, native form controls won't automatically switch to dark styling unless you explicitly set color-scheme: dark on the :root or body element. Add :root { color-scheme: light dark; } to your global styles to enable automatic adaptation of native UI elements.
The best practice is a three-state toggle: Light, Dark, and Auto (follow system). Store the user's choice in localStorage and apply the appropriate class or attribute to the <html> element. Use CSS custom properties (variables) scoped to [data-theme="dark"] and [data-theme="light"] selectors for full control. In Auto mode, fall back to prefers-color-scheme media queries.
prefers-color-scheme in DevTools?
Yes! In Chrome DevTools, open the Command Menu (Cmd+Shift+P / Ctrl+Shift+P), type "Show Rendering," and in the Rendering tab you'll find an option to emulate prefers-color-scheme. In Firefox, open DevTools Settings and check "Enable prefers-color-scheme simulation." This tool above provides a live preview alternative without opening DevTools.
Indirectly, yes. Google considers Core Web Vitals and user experience as ranking factors. A well-implemented dark mode reduces eye strain, improves readability in low-light environments, and can increase time-on-page. Additionally, respecting user preferences signals good UX design. While prefers-color-scheme itself isn't a direct ranking signal, the improved engagement metrics can positively impact SEO.
Define a set of colors for light and dark themes. Get the CSS custom properties snippet. Toggle live.
Start from a base color and use `oklch(from color l c h)` to create lighter or darker variants. Copy the code.
Simulate forced‑colors mode and see how your site looks. Adjust CSS system colors. Make your design accessible.
Generate a palette of N colors that are maximally distinguishable for common color vision deficiencies. Copy the hex codes.
Stack multiple background images and blend them with colors. Create unique textures. Copy the CSS code instantly.
See which fonts map to generic families (serif, sans‑serif, monospace) on different operating systems. A handy reference.
See the difference between :focus and :focus‑visible on interactive elements. Learn which to use for better UX.
Browse the fonts installed on your system and type a custom phrase to see how it looks. Uses Local Font Access API where available.
Paste your full CSS and HTML; automatically identify and extract the styles needed for the visible part. Reduce render‑blocking resources.
Design a realistic neon sign text with multiple layers of glow. Copy the CSS and HTML. Perfect for headers.
Simulate reduced motion preference and test your animations. Copy the media query snippet. Keep your users safe.
Apply the drop‑shadow() filter and compare it with box‑shadow. See how it follows the contour of transparent images. Copy code.
Highlight elements with aria‑describedby and see the linked description text. Verify a11y annotations.
Toggle OpenType features like liga, smcp, tnum, and see the text update. Support for variable fonts. Typography nerds.
Apply content‑visibility: auto to off‑screen sections and see the rendering cost drop. Demos for infinite scroll optimization.
Apply East Asian glyph variants like jis78, proportional-width, ruby. See the difference instantly. For CJK typography.
New CSS text‑spacing property for fine control over punctuation spacing. See the effect live. For advanced typography.
Design a custom focus indicator with outline, offset, and box‑shadow. Preview on interactive elements. Copy the CSS.
See how a full paragraph looks with your chosen text and background colors. Not just a ratio; the real appearance.
Toggle between full and reduced motion on a live animated page. See how to design for vestibular disorders. Educational.
Create vertically oriented text layouts with `writing‑mode`. See the effect and copy the complete CSS. For vertical languages.
Create glowing, neon‑style text effects with multiple text‑shadows. Adjust colors and intensity. Copy the CSS.
Full‑screen random colour changes at a slow pace. Use it as a dynamic background for meditation or focus.
Beautify and format your CSS stylesheets instantly. Organize, minify, or prettify CSS code for better readability. Processed securely on client-side.
Style a drop cap using the initial‑letter property. Set size and sink. Modern alternative to pseudo‑element hacks.
Style a drop cap using the initial‑letter property. Set size and sink. Modern alternative to pseudo‑element hacks.
Test overscroll‑behavior: contain to prevent background scroll or pull‑to‑refresh. See the effect in a live demo.
Convert normal text to Unicode mathematical bold, italic, script, fraktur, and double‑struck. Copy rich text for anywhere.
Toggle scroll‑behavior: smooth and click anchor links to see the scrolling animation. Implement modern UX.
Build a complete font‑stack for your website. Choose a primary font and get the best fallback options for different OS. Copy the CSS.