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
.)
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
Indicates that user has notified the system that they prefer an interface that has a light theme, or has not expressed an active preference.
dark
Indicates that user has notified the system that they prefer an interface that has a dark theme.
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;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Media Queries Level 5
The definition of 'prefers-color-scheme' in that specification. |
编者草案 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
prefers-color-scheme
media feature
|
Chrome 完整支持 76 | Edge 完整支持 79 | Firefox 完整支持 67 | IE 不支持 No | Opera 完整支持 62 | Safari 完整支持 12.1 | WebView Android 完整支持 76 | Chrome Android 完整支持 76 | Firefox Android 不支持 No | Opera Android 完整支持 54 | Safari iOS 完整支持 13 | Samsung Internet Android 完整支持 12.0 |
no-preference
value
弃用
非标
|
Chrome 不支持 76 — 80 | Edge 不支持 79 — 80 | Firefox 不支持 67 — 79 | IE 不支持 No | Opera 不支持 62 — 71 | Safari 完整支持 12.1 | WebView Android 不支持 76 — 80 | Chrome Android 不支持 76 — 80 | Firefox Android 不支持 67 — 79 | Opera Android 完整支持 54 | Safari iOS 完整支持 13 | Samsung Internet Android 不支持 12.0 — 13.0 |
完整支持
不支持
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。