大网数据广告活动
Web 标准与前端开发

`inverted-colors` CSS media feature

· 52CE 我爱测

The **`inverted-colors`** CSS media feature is used to test if the user agent or the underlying operating system has inverted all colors.

The inverted-colors CSS media feature is used to test if the user agent or the underlying operating system has inverted all colors.

Inversion of colors can have unpleasant side effects, such as shadows turning into highlights, which can reduce the readability of the content. Using this media feature, you can detect if inversion is happening and style the content accordingly while respecting user preference.

Syntax

/* Keyword value */
@media (inverted-colors: inverted) {
  /* styles to apply if inversion of colors is detected */
}

The inverted-colors feature is specified as one of the following keyword values:

  • none
    • : Indicates that the colors are displayed normally and no inversion of colors has happened. This keyword value evaluates as false.
  • inverted
    • : Indicates that all pixels within the displayed area have been inverted. This keyword value evaluates as true.

Examples

Applying styles if color inversion is detected

This example demonstrates the effects of both inverted-colors media feature keyword values and when the inverted-colors media feature is not supported.

HTML

<p>
  If color inversion is detected, this text will appear blue on white (the
  inverse of yellow on black) along with a line over the text. If no color
  inversion is happening, the text will appear red on light gray without the
  line over the text.
</p>
<p>
  If the text is gray and no overline is present, it means your browser doesn't
  support the
  <code>inverted-colors</code> media feature.
</p>

CSS

p {
  color: gray;
}

@media (inverted-colors: inverted) {
  p {
    background: black;
    color: yellow;
    text-decoration: overline;
  }
}

@media (inverted-colors: none) {
  p {
    background: #eeeeee;
    color: red;
  }
}

Result

Applying styles if color inversion is detected

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。