If you have set privacy.resistFingerprinting
to true, prefers-color-scheme
preference is overridden to light
.
Alternately, users can create the numeric preference ui.systemUsesDarkTheme
to override the default behavior and return light
(value: 0), dark
(value: 1), or no-preference
(value: 2). (Any other value causes Firefox to return light
.)
The prefers-color-scheme
CSS media feature is used to detect if the user has requested the system use a light or dark color theme.
light
dark
The elements below have an initial color theme. They can be further themed according to the user's color scheme preference.
<div class="day">Day (initial)</div> <div class="day light-scheme">Day (changes in light scheme)</div> <div class="day dark-scheme">Day (changes in dark scheme)</div> <br> <div class="night">Night (initial)</div> <div class="night light-scheme">Night (changes in light scheme)</div> <div class="night dark-scheme">Night (changes in dark scheme)</div>
.day { background: #eee; color: black; } .night { background: #333; color: white; } @media (prefers-color-scheme: dark) { .day.dark-scheme { background: #333; color: white; } .night.dark-scheme { background: black; color: #ddd; } } @media (prefers-color-scheme: light) { .day.light-scheme { background: white; color: #555; } .night.light-scheme { background: #eee; color: black; } } .day, .night { display: inline-block; padding: 1em; width: 7em; height: 2em; vertical-align: middle; }
Specification | Status | Comment |
---|---|---|
Media Queries Level 5 The definition of 'prefers-color-scheme' in that specification. | Editor's Draft | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
prefers-color-scheme media feature |
76 | 79 | 67 | No | 62 | 12.1 |
no-preference value
|
76 — 80 | 79 — 80 | 67 — 79 | No | 62 — 71 | 12.1 |
Mobile | ||||||
---|---|---|---|---|---|---|
prefers-color-scheme media feature |
76 | 76 | No | 54 | 13 | 12.0 |
no-preference value
|
76 — 80 | 76 — 80 | 67 — 79 | 54 | 13 | 12.0 — 13.0 |
© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme