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.

HTML

<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>
					

CSS

.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.
编者草案 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

另请参阅

元数据

  • 最后修改: