forced-colors CSS media feature is used to detect if the 用户代理 has enabled a forced colors mode where it enforces a user-chosen limited color palette on the page.

注意: This feature is not supported by any user agent and its specifics are subject to change.

句法

forced-colors media feature indicates whether or not the browser is currently in forced-colors mode.

none

Forced colors mode is not active; the page’s colors are not being forced into a limited palette.

active
Indicates that forced colors mode is active. The browser provides the color palette to authors through the CSS system color keywords and, if appropriate, it triggers the appropriate value of prefers-color-scheme so that authors can adapt the page.

用法注意事项

Properties affected by forced-color mode

In forced colors mode, the values of the following properties are treated as if they have no author-level values specified. That is, user-specified values (if any) or browser-specified values are used instead.

可以使用 system color keywords with any property other than those listed above, to ensure that the rest of the page integrates with the restricted color palette available in forced colors mode.

User preferences

Currently no user agent implements this feature, although various operating systems do support such preferences and if this media query is ever implemented user agents will likely rely on the settings provided by the operating system in use.

范例

注意: No browser currently implements this feature so the following example will not work.

This example has an annoying color palette by default. This example does not take advantage of the colors provided by the user agent.

HTML

<div class="colors">weird color box</div>
					

CSS

.colors {
  background-color: red;
  color: grey;
}
@media (forced-colors: active) {
  .colors {
    background-color: white;
    color: black;
  }
}
					

结果

规范

规范 状态 注释
Media Queries Level 5
The definition of 'forced-colors' 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
forced-colors media feature Experimental Chrome 完整支持 79 注意事项 Disabled
完整支持 79 注意事项 Disabled
注意事项 bug 970285 .
Disabled ). To change preferences in Chrome, visit
Edge 完整支持 79 Firefox 完整支持 81 Disabled
完整支持 81 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 970285 .
Chrome Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 970285 .
Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 970285 .

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Conditional Rules
  4. Media Queries
  5. 指南
    1. Using feature queries
    2. Testing media queries programmatically
    3. Using Media Queries for Accessibility
    4. Using media queries
  6. At-Rules
    1. @document
    2. @import
    3. @media
    4. @supports

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1