Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox: How to test prefers-color-scheme?

In Firefox 67, one can use media queries to detect user preference on light or dark theme.

In my version of Firefox (under Ubuntu), it seems that my preference is light theme. That is, the following CSS gives a blue background:

@media (prefers-color-scheme: light) {     :root {}    body {      background-color: blue;    }  }

How can I change my Firefox preferences so that prefers-color-scheme: dark evaluates to true?

I found an add-on that seems to do the trick, but I must be doing something wrong with my own CSS, as it does not work on my page. Dark Website forcer

like image 289
Per Alexandersson Avatar asked May 31 '19 20:05

Per Alexandersson


People also ask

How do I find my preference color scheme?

Web browser support as of March 2019 For current browser support, check out https://caniuse.com/#search=prefers-color-scheme.

Can Firefox Force dark mode?

You can also trigger toggling the dark mode with the hot key <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> (customizable in the Firefox add-on settings). This extension only works with Firefox v95 or higher. You can use a toolbar button to toggle whether it should force a dark mode or not.

What media query property can we use to check if user has chosen the dark mode in their browser or system?

As dark mode is reported through a media query, you can easily check if the current browser supports dark mode by checking if the media query prefers-color-scheme matches at all.


1 Answers

Good news -- from Firefox 87 this is now enabled by default, without the need to set a configuration flag! You can find it in the inspector tab:

The Firefox Developer tools, with perfers color scheme toggles circled

  • Choosing the sun button simulates light mode;
  • Choosing the moon button simulates dark mode;
  • With no button selected, your operating system default will be used, as per normal.

In some older versions of Firefox, this feature existed behind a flag. To test on one of those versions, you can thus enable this by going to about:config, and setting the devtools.inspector.color-scheme-simulation.enabled property to true. Once that's done, you'll find the controls for it in the same place as in the modern devtools, but as a single paintbrush icon rather than today's sun/moon toggle buttons.

like image 172
Toastrackenigma Avatar answered Oct 05 '22 03:10

Toastrackenigma