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

`<meta name="color-scheme">` HTML attribute value

· 52CE 我爱测

The **`color-scheme`** value for the `name` attribute of the meta element indicates a suggested color scheme that user agents should use for a page. If specified, you define the color scheme using a `content` attribute in the `<meta>` element with a valid CSS color-scheme value.

The color-scheme value for the name attribute of the meta element indicates a suggested color scheme that user agents should use for a page. If specified, you define the color scheme using a content attribute in the <meta> element with a valid CSS color-scheme value.

The theme color works at the document level in the same way that the CSS color-scheme property specifies the preferred and accepted color schemes of individual elements. The primary use for <meta name="color-scheme"> is to indicate compatibility and order of preference for light and dark color modes. For example, to indicate that a document prefers dark mode but also supports light mode:

<meta name="color-scheme" content="dark light" />

Your styles can adapt to the current color scheme using the @media/prefers-color-scheme CSS media feature.

Usage notes

A <meta name="color-scheme"> element has the following additional attributes:

  • content
    • : A <meta> element with name=color-scheme must have a content attribute that defines the color scheme as a CSS color-scheme value. The content attribute may be one of the following:
      • normal
        • : The document is unaware of color schemes and should be rendered using the default color palette.
      • light, dark, light dark, dark light
        • : One or more color schemes supported by the document. Multiple color schemes indicates that the first scheme is preferred by the document, but that the second scheme is acceptable if the user prefers it. Specifying the same color scheme multiple times has the same effect as specifying it once.
      • only light
        • : Indicates that the document only supports light mode, with a light background and dark foreground colors. only dark is invalid, because forcing a document to render in dark mode when it isn't compatible can result in unreadable content and all major browsers default to light mode if not otherwise configured.

Examples

Using a color-scheme keyword

The following example indicates to the browser that the page supports both light and dark themes. Whether the light or dark color scheme is used depends on user preferences such as OS-level settings or the browser settings:

<meta name="color-scheme" content="light dark" />

Specifications

Browser compatibility

See also

  • color-scheme CSS property
  • @media/prefers-color-scheme media query

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

资料来源与适用范围

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

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

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