CSS Dark Mode
CSS
What is CSS Color Mode?
CSS color mode refers to designing your website to support dark mode and light mode themes — automatically switching based on the user’s system settings.
Why Support Color Modes?
- Improves user experience
- Reduces eye strain in low light (dark mode)
- Makes your site look modern and adaptive
How to Detect User’s Preference
Use the @media (prefers-color-scheme) CSS media feature.
The browser automatically applies the correct mode based on the user’s OS settings.
Style Specific Elements
Combine with CSS Variables for Easy Theming
This makes it super easy to switch themes site-wide!
Feature | What It Does |
---|---|
@media (prefers-color-scheme: dark) | Targets users in dark mode |
@media (prefers-color-scheme: light) | Targets users in light mode |
CSS Variables | Makes color theming easier and reusable |