Skip to main content

Google Chrome 98 re-adds 'only' keyword for color-scheme by default

Starting with Google Chrome 98, the 'only' keyword has been re-added to the specification for color-scheme as a way of per-element opt-out of color-scheme override like forced darkening. Meaning, this feature can essentially be used to do per element opt-out of color-scheme overrides like forced darkening.

If the user has indicated an overriding preference for a particular color scheme, and the author has not disallowed this (by using the only keyword), the user agent may override the color scheme, forcing the used color scheme to the user’s preferred color scheme. If the element does not support that color scheme, the user agent must also auto-adjust other colors into this chosen color scheme, such as by inverting their brightness, while preserving any color contrast necessary for the readability of the page. In this case, UA may also auto-adjust colors within replaced elements, background images, and other external resources as appropriate.

The specifics of such auto-adjustments are UA-defined and can differ from UA to UA. But it is not intended to force all colors into a fixed palette, as forced colors mode does, only to force all colors on the page to conform to either a dark or light color scheme.

For example, a UA might have a “dark room” mode, which forces all pages into a dark color scheme.

For pages that already support dark color schemes, and have indicated so using the color-scheme property or color-scheme meta name, this has no effect other than reporting a dark value for the prefers-color-scheme media query and selecting a dark used color scheme.

But for pages that do not explicitly support a dark color scheme, and have not explicitly forbidden this auto-adjustment by specifying color-scheme: only light, this mode triggers auto-adjustment of the page’s colors to force the page to conform to the desired dark color scheme.

  • For elements with color-scheme 'light', the color-scheme will be forced to dark and forced darkening will be performed on colors and images as necessary.
  • For elements with color-scheme 'dark', no forced darkening will be applied.
  • For elements with 'only light', the color-scheme will stay light, and no force darkening will be applied. This behavior is behind a runtime flag.

With that runtime flag disabled, 'only light' will behave as 'light'.

Source: 1, 2, 3


Comments