RSS Amplifier

Duncan McDougall | Web Developer · Dec 4, 2019

Dark Mode CSS with the prefers-color-scheme media query

0
Sign in to vote or save

Duncan McDougall

Duncan McDougall and heir apparent

prefers-color-scheme is a new-ish CSS media query that lets developers define styles tailored to a visitor's color scheme system setting.

@media (prefers-color-scheme: light|dark|no-preference) { ... }

Picture a webpage with a white background with mostly black text. If a visitor has their operating system's colour scheme set to Dark, a few line of CSS is all that's needed to make the website fall in line.

@media (prefers-color-scheme: dark) {
body {
background: #000;
color: #ccc;
}
}

Browser Support

Data on support for the prefers-color-scheme feature across the major browsers from caniuse.com

Resources

Read the original on belter.io

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.