🔨 All in one Utilities

prefers-color-scheme Generator

Great utilities that help you design, program and maintain your website

utilities for you to make a website
Home » Utilities » prefers-color-scheme Generator

🌓prefers-color-scheme Generator

This tool provides the basic CSS boilerplate for creating a dark and light theme based on the user's system preferences.

Respecting a user's preference for a dark or light theme is a key part of modern web design and accessibility. The `prefers-color-scheme` CSS media feature makes this possible. This generator provides the essential CSS boilerplate you need to get started. It shows you how to set up CSS variables for your light and dark theme colors, and how to use the media query to apply the dark theme when the user has it enabled in their operating system.

Frequently Asked Questions

How does `prefers-color-scheme` work?

It's a CSS media feature that checks the user's operating system setting for light or dark mode. You can write CSS rules inside `@media (prefers-color-scheme: dark)` that will only apply when the user is in dark mode.

Why use CSS variables for theming?

Using CSS variables (`--variable-name`) makes theming much easier. You can define all your theme colors in one place (`:root`), and then the media query only needs to change the variable values, rather than you having to override styles for every single element.

Related Utilities

main>