skip to Main Content

Is there an official way to know if light-dark() is supported in google chrome (Version 125.0.6422.142 (Official Build) (64-bit)) besides caniuse…

According to caniuse it is supported but I cannot seem to get it to work.
(Works fine in edge)

I used the example code straight from mdn web docs

:root {
  /* this has to be set to switch between light or dark */
  color-scheme: light dark;
  --light-bg: ghostwhite;
  --light-color: darkslategray;
  --light-code: tomato;
  --dark-bg: darkslategray;
  --dark-color: ghostwhite;
  --dark-code: gold;
}

* {
  background-color: light-dark(var(--light-bg), var(--dark-bg));
  color: light-dark(var(--light-color), var(--dark-color));
}

code {
  color: light-dark(var(--light-code), var(--dark-code));
}
<h1><code>light-dark()</code> CSS function</h1>
<section>
  <h2>Automatic</h2>
  <p>This section will react to the users system or user agent setting.</p>
</section>
<section class="light">
  <h2>Light</h2>
  <p>
    This section will be light due to the <code>color-scheme: light;</code>.
  </p>
</section>
<section class="dark">
  <h2>Dark</h2>
  <p>This section will be dark due to the <code>color-scheme: dark;</code>.</p>
</section>

even tried the meta tag
<meta name="color-scheme" content="light dark">

in chrome it only displays the light version even if I have dark mode selected in settings.
(Using edge the result changes depending on light or dark mode selected)

In using the dev tools emulator it works but I believes that is because the emulator uses the @media which is what I thought light-dark() was supposed to avoid.

2

Answers


  1. Chosen as BEST ANSWER

    So I believe I got to the bottom of it .

    In order to get the Prefers-Color-Scheme header to change (In turn allowing all the color css parts to function ) in chrome - It takes the setting from the Windows setting under personalization - colors NOT the appearance setting in the browser setting (That makes absolutly no sense to me why they would do that but...)

    In edge, it resposnds to the appearance setting in the browser.

    two wasted days but at least I know now.


  2. you can always prefer to this website to know which browse support these functionality.

    https://caniuse.com/?search=prefers-color-scheme

    and it support the newer version of chrome.

    may be there be a css code that already had set background color for you so try to find that code or there may be chrome flag issue.

    you can also use developer tool to find out if there are any conflict.

    All the best!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search