Widely availableA valuable enhancement for accessible theming and component contrast tuning.

Overview

prefers-contrast detects whether the user has requested more or less contrast. It helps interfaces respond to explicit user needs without maintaining entirely separate themes.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
96
96
101
14.1
96
14.5
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
@media (prefers-contrast: more) {
  :root {
    --border-color: #000000;
    --text-color: #000000;
    --bg-subtle: #ffffff;
  }

  .card {
    border: 2px solid var(--border-color);
  }

  .muted-text {
    color: var(--text-color);
  }
}

@media (prefers-contrast: less) {
  :root {
    --text-color: #666666;
  }
}

Live demo

standardcontrast

prefers-contrast standardcontrast demo.

PreviewFullscreen

highcontrastsupport

prefers-contrast highcontrastsupport demo.

PreviewFullscreen

buttonexample

prefers-contrast buttonexample demo.

PreviewFullscreen

Use cases

  • Higher-contrast UI

    Increase borders, text contrast, and focus visibility when the user has asked for stronger separation.

  • Preference-aware theming

    Adjust visual density or contrast style without forcing a full theme switch.

Cautions

  • The media query is a hint about preference, not a substitute for meeting baseline contrast requirements everywhere.
  • Keep the default theme accessible even when the user has not set a system-level preference.

Accessibility

  • This query directly supports users who need stronger contrast cues.
  • Contrast adaptations should also preserve focus styles, borders, and distinguishable states.

Powered by web-features