ZL
About Articles Contact
Published on Aug 25, 2022
Filed under:
#css

Understanding the color-scheme property

You would have heard of the CSS color-scheme property if you are interested in adding a dark theme to your website. Here’s what it looks like:

:root {
color-scheme: light dark;
}

color-scheme tells the browser to render user-agent stylesheets according to the user’s preferred color scheme (which is set in their operating system).

There are three possible values (and it’s super easy to understand):

  • light: Browser will render styles according to the light scheme only
  • dark: Browser will render styles according to the dark scheme only
  • light dark (or dark light): Browser will render styles according to the scheme the user prefers

This means:

  • color-scheme: light will give black text on a white background
  • color-scheme: dark will give white text on a black background
  • color-scheme: light dark or dark light will give either light or dark depending on the user’s color scheme preference in their operating system.

Is color-scheme necessary?

Most articles would recommend you use color-scheme.

But nope. color-scheme is not necessary.

color-scheme is not necessary because it only changes the colors in the user-agent stylesheet. If you are confident you would override all user-agent stylesheet colors, there’s no need to add this extra line.

In fact, I’d argue it’s safer to omit color-scheme when you’re building Light and Dark themes… but that’s a topic for another day when I consolidate all the information I found about creating Light and Dark themes.

Just my two cents.

Update: Setting color-scheme to would change scrollbar colors. So the property is no longer unnecessary. I’m still hesitant about using it because it may introduce more problems… but I’ll leave that conversation for another day.

Previous Here’s how to quickly test components that use container queries Next The Magical Dev School Student Portal is live!

Join My Newsletter

I share what I’m learning on this newsletter: code, building businesses, and living well.

Sometimes I write about technical deep-dives, product updates, musings on how I live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you at least one insightful piece every week.

If you’re into making things and growing as a person, you’ll probably feel at home here.

“

Zell’s writing is very accessible to newcomers because he shares his learning experience. He covers current topics and helps all readers level up their web development skills. Must subscribe.

Chen Hui Jing
Chen Hui Jing — Web Developer
The Footer

General

Home About Contact Testimonials Tools I Use

Projects

Magical Dev School Splendid Labz

Socials

Youtube Instagram Tiktok Github Bluesky X

Follow Along

Email RSS
© 2013 - 2026 Zell Liew / All rights reserved / Terms