CSS defines color values that follow system preferences (#tilPost)

I learned something exciting from Jim Nielsen today. Jim shared that CSS defines system color values that follow the system color preferences (light and dark mode). If you want to learn more about the nitty-gritty details, read his …


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I learned something exciting from Jim Nielsen today. Jim shared that CSS defines system color values that follow the system color preferences (light and dark mode). If you want to learn more about the nitty-gritty details, read his post or have a look at the CSS Color Module Level 4 specification.

This post shares my discoveries after playing around with system color values such as Canvas and CanvasText.

You can find all defined system color values in the example below. Change your color preferences and see the colors below adjust!

You can see the colors react to system preferences in Chrome and Safari in the video below, too.

Here are a few things I noticed. ?

At the time of writing, it appears that only Chromies' and Safari's system color values take the system preferences into consideration. I assume that there's no Firefox support because Firefox doesn't support the color-scheme CSS property yet. ?‍♂️But I can't be sure about that either because a supported color-scheme property doesn't mean that all the system colors work correctly. Read on!

Even though the specification defines 15 system colors, not all of them function today. E.g. ButtonBorder, Mark and MarkText don't seem to be implemented in Chromiums or Safari at all.

And lastly, what's interesting is that Chrome and Safari define slightly different colors for some system colors. Chrome defines Canvas as pure black (#000) when users prefer dark mode. Safari on the other hand, is going with a dark gray (#e1e1e1).

:root { 
  /*
     "Canvas" becomes the following ?
     
     Light system preferences:
       - Chrome: #fff
       - Safari: #fff
     Dark system preferences: 
       - Chrome: #000
       - Safari: #e1e1e1
  */
  background-color: Canvas;
  /* 
     "CanvasText" becomes the following ?

     Light system preferences:
       - Chrome: #000
       - Safari: #000
     Dark system preferences: 
       - Chrome: #fff
       - Safari: #fff
  */
  color: CanvasText;
}

Jim pointed out that you can use system colors to make websites feel more "native". If you're building a web app that should blend in nicely on iOS, the correct colors are the key and system colors provided by Safari will come in handy!

It's probably not the time yet...

It feels to me that it's too early to entirely rely on system color CSS values because there's no cross-browser support yet, and except for Canvas and CanvasText I don't have a great feeling about the other colors.

Nevertheless, it's a great thing to be aware of these system colors. If/when I tackle dark mode for this site, I'll check if I can use provided system colors!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2021-06-05T22:00:00+00:00) CSS defines color values that follow system preferences (#tilPost). Retrieved from https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/

MLA
" » CSS defines color values that follow system preferences (#tilPost)." Stefan Judis | Sciencx - Saturday June 5, 2021, https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/
HARVARD
Stefan Judis | Sciencx Saturday June 5, 2021 » CSS defines color values that follow system preferences (#tilPost)., viewed ,<https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » CSS defines color values that follow system preferences (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/
CHICAGO
" » CSS defines color values that follow system preferences (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/
IEEE
" » CSS defines color values that follow system preferences (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/. [Accessed: ]
rf:citation
» CSS defines color values that follow system preferences (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2021/06/05/css-defines-color-values-that-follow-system-preferences-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.