CSS inverted-colors Media Feature

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The inverted-colors media feature tests whether the user agent or OS has inverted all colors in the displayed area.

Use @media (inverted-colors: inverted) to adapt when inversion is on (for example iOS Smart Invert), and @media (inverted-colors: none) when colors are normal. Inversion can turn shadows into highlights and hurt readability — this query lets you soften those side effects while respecting the user’s setting.

Limited availability Not Baseline

Mainly supported in Safari. Chrome, Edge, and Firefox do not ship it yet. Use as progressive enhancement only — never require it for readable defaults.

Not dark mode.

Dark theme preference is prefers-color-scheme. inverted-colors is a separate accessibility inversion signal.

CSS Syntax

syntax.css
@media (inverted-colors: none | inverted) { … }

Always wrap the feature in parentheses. Invalid forms like @media inverted-colors(inverted) do not work.

Feature Values

ValueDescriptionTry it
noneColors display normally (no system inversion)Try it
invertedAll displayed pixels are invertedTry it
Image tweakCounter-invert photos so they look natural under OS inversionTry it
Combined queryPair with a media type, e.g. screen and (inverted-colors: inverted)Try it

How to Use inverted-colors

Keep normal styles solid, then enhance when inversion is detected.

  1. Write readable defaults with good contrast (no media query required).
  2. Add @media (inverted-colors: inverted) for inversion-aware tweaks.
  3. Reduce heavy shadows/gradients that become harsh after invert.
  4. Optionally protect photos with filter: invert(1) so they look correct after the OS invert.
PieceRequired?Role
@mediaYesWraps the media feature
KeywordYesnone or inverted
Default stylesYesMust work when the feature is unsupported
Safari testingRecommendedEnable Smart Invert / increase contrast tools to verify

Live Preview

Reports what matchMedia returns on this browser. On Chrome/Firefox you will often see no support; Safari with Smart Invert can match inverted.

Detected inverted-colors queries

Gray sample = default. Real query styles apply only when the matching media feature is supported and active.

Inversion detection

Inverted-colors sample

(inverted-colors: none) (inverted-colors: inverted)

Checking…

CSS Examples

Each snippet focuses on inverted-colors. View Output shows the intended look; many desktop browsers will not match — use Try It Yourself and Safari when possible.

Example 1 — Styles When Inverted

Adapt text and background when the OS inverts colors.

CSS
p {
  color: #64748b;
}

@media (inverted-colors: inverted) {
  p {
    background: #000;
    color: #ff0;
    text-decoration: overline;
  }
}
Try It Yourself

How It Works

  1. Start with a default. Gray text works everywhere, including unsupported browsers.
  2. Detect inversion. @media (inverted-colors: inverted) runs only when the OS inverts pixels.
  3. Pick intentional colors. After OS invert, yellow-on-black becomes blue-on-white — plan for that flip.
  4. Mark the state. An overline helps verify the query during testing.

Example 2 — Styles When Not Inverted

Target the normal (non-inverted) path explicitly.

CSS
p {
  color: #334155;
}

@media (inverted-colors: none) {
  p {
    color: #dc2626;
  }
}
Try It Yourself

How It Works

  1. Keep a fallback color. Slate text shows if the feature is missing.
  2. Match none. Applies when the browser supports the feature and inversion is off.
  3. Enhance only then. Red text is an intentional non-inverted style.
  4. Unsupported = default. Chrome/Firefox typically stay on the first rule.

Example 3 — Protect a Photo

Counter-invert images so photos look natural under OS inversion.

CSS
img {
  max-width: 200px;
}

@media (inverted-colors: inverted) {
  img {
    filter: invert(1);
  }
}
Try It Yourself

How It Works

  1. Leave images alone by default. No filter when colors are normal.
  2. Detect inverted. The media query fires when the OS flips every pixel.
  3. Invert again. filter: invert(1) cancels the system invert for that image.
  4. Use sparingly. Icons and UI chrome may need different treatment than photos.

Edge Cases & Pitfalls

If nothing changes on desktop Chrome, that is expected — check these next.

support

Safari-first today

Most Chromium and Firefox builds do not match. Defaults must already be readable without the query.

vs dark

Not prefers-color-scheme

Dark mode and color inversion are different OS settings. Style them separately.

plan

Colors flip again

Styles you set under inverted are themselves inverted by the OS. Design for the final on-screen result.

shadows

Shadows become highlights

Soft shadows and translucent overlays can look harsh after invert. Simplify them under inverted.

syntax

Parentheses required

Use @media (inverted-colors: inverted). Forms without parentheses are invalid.

Browser Support

inverted-colors is a browser media feature. Node.js, Deno, and Bun do not evaluate it.

✓ Limited availability

inverted-colors

Supported in Safari 9.1+ and Safari on iOS 10+. Chrome, Edge, Opera, and Firefox do not support it in production (Firefox may have a disabled flag). Use as progressive enhancement.

18% Global reach
Google Chrome —
No support
Mozilla Firefox —
No / flag
Apple Safari 9.1+
Full support
Microsoft Edge —
No support
Opera —
No support
Samsung Internet —
No support
Internet Explorer —
No support
@media (inverted-colors) Safari primarily

Bottom line: Teach the syntax and ship safe defaults. Rely on Safari for real matching. It is not a runtime API.

Key Takeaways

  • Role: detect OS/user-agent color inversion.
  • Values: none and inverted inside @media (…).
  • Not dark mode: separate from prefers-color-scheme.
  • Practice: progressive enhancement; Safari is the main test target.

One line: detect system color inversion, fix harsh side effects, and never depend on the query for basic readability.

Frequently Asked Questions

It detects whether the user agent or OS has inverted all displayed colors (for example iOS Smart Invert). Use @media (inverted-colors: inverted) to adapt styles when inversion is active.
Two keywords: none (colors display normally) and inverted (all pixels in the displayed area are inverted).
No. Dark mode uses prefers-color-scheme. inverted-colors detects system-level color inversion, which flips colors for accessibility — a different preference.
Use it as progressive enhancement: soften shadows that become highlights, protect images that look wrong when inverted, and keep text readable after the OS flips colors.
Primarily Safari (macOS 9.1+, iOS 10+). Chrome, Edge, and Firefox do not support it in production yet. Treat it as Limited availability enhancement.
No. It is a CSS media feature evaluated by the browser layout engine, not a Node.js or server runtime feature.

Next: light-level

Learn the light-level media feature for ambient lighting conditions.

light-level tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful