CSS prefers-contrast Media Feature

Beginner
6 min read
Updated: Nov 2026
3 examples
Live preview

Definition and Usage

The prefers-contrast media feature detects whether a user has requested more contrast, less contrast, or a custom color palette.

Use it to strengthen boundaries, increase text contrast, or avoid overly stark palettes. It complements good default contrast; it does not excuse low-contrast base styles.

Baseline · Newly available.

This preference query is designed for progressive enhancement. Browsers that do not support it keep the default styles.

Tip Not the same as forced colors

prefers-contrast reports a preference. forced-colors reports that the browser is actively substituting colors. A custom forced palette can cause custom to match.

CSS Syntax

syntax.css
@media (prefers-contrast:no-preference | more | less | custom) { … }

Wrap the feature in parentheses and put the conditional CSS inside the media block.

Feature Values

ValueDescriptionTry it
no-preferenceNo contrast preference has been expressedTry it
moreThe user prefers stronger contrastTry it
lessThe user prefers lower contrastTry it
customThe user uses a custom palette that does not map to more or lessTry it

How to Use prefers-contrast

Use the preference to enhance a solid, accessible default.

  1. Build a readable default that already meets contrast guidance.
  2. Use more to strengthen text, borders, and focus indicators.
  3. Use less only to soften non-essential contrast without hiding content.
  4. Test custom and forced-color environments without relying on color alone.
PieceRequired?Role
@mediaYesWraps the preference query
prefers-contrastYesNames the media feature
Accessible defaultsYesWork when no query matches
Real-device testingRecommendedConfirms operating-system behavior

Live Preview

Your browser evaluates each prefers-contrast value below through matchMedia.

Detected preference

Change the related operating-system accessibility or appearance setting, then recheck.

Preference detection
no-preferencemorelesscustom

Checking…

CSS Examples

Each example keeps the default usable, then responds to prefers-contrast. Open Try It Yourself for a live editor.

Example 1 — Strengthen a Card

Increase border and text contrast when more is requested.

CSS
.card {
  color: #475569;
  border: 1px solid #cbd5e1;
}

@media (prefers-contrast: more) {
  .card {
    color: #0f172a;
    border: 3px solid currentColor;
  }
}
Try It Yourself

How It Works

  1. The default card is already readable.
  2. The query detects a request for more contrast.
  3. Text becomes darker and the border thicker.
  4. Using currentColor keeps the border coordinated.

Example 2 — Soften a Decorative Surface

Reduce harsh decoration while keeping text readable.

CSS
.notice {
  color: #111827;
  background: #ffffff;
  border: 2px solid #111827;
}

@media (prefers-contrast: less) {
  .notice {
    border-color: #94a3b8;
    background: #f8fafc;
  }
}
Try It Yourself

How It Works

  1. The normal notice uses a strong boundary.
  2. The query detects a lower-contrast preference.
  3. Only decorative surface colors soften.
  4. Important text remains dark and legible.

Example 3 — Handle a Custom Preference

Avoid decorative effects when a custom contrast palette is active.

CSS
.button {
  box-shadow: 0 4px 12px rgb(15 23 42 / 25%);
}

@media (prefers-contrast: custom) {
  .button {
    box-shadow: none;
    outline: 2px solid currentColor;
  }
}
Try It Yourself

How It Works

  1. The default uses a decorative shadow.
  2. The custom query covers user-defined palettes.
  3. A current-color outline survives palette changes.
  4. The control remains identifiable without the shadow.

Edge Cases & Pitfalls

Contrast preferences vary by platform, and support arrived later than other preference queries.

baseline

Good defaults still matter

Every user needs readable text even when no preference query matches.

forced

Check forced-colors too

A forced palette changes actual colors; use the separate forced-colors feature when needed.

meaning

Do not rely on color alone

Use labels, icons, underlines, and clear boundaries for important states.

support

Treat as enhancement

Older browsers ignore the query and keep your accessible default styles.

Browser Support

prefers-contrast is a browser media feature. Node.js, Deno, and Bun do not apply CSS media queries.

✓ Baseline · Newly available

prefers-contrast

Available across current major browsers; older releases may ignore it.

88% Modern browsers
Google Chrome 96+
Full support
Mozilla Firefox 101+
Full support
Apple Safari 14.1+
Full support
Microsoft Edge 96+
Full support
Opera 82+
Full support
Samsung Internet 17+
Full support
Internet Explorer No
No support
@media (prefers-contrast) Progressive enhancement

Bottom line: Use as progressive enhancement over an accessible default. Test platform settings because available preferences differ.

Key Takeaways

  • Role: respond to a user’s prefers-contrast setting.
  • Values: no-preference, more, less, custom.
  • Default: keep the page accessible when the query is unsupported.
  • Test: use actual operating-system preference settings.

One line: use prefers-contrast to respect user preferences without weakening the default experience.

Frequently Asked Questions

It detects whether the user prefers more contrast, less contrast, a custom palette, or has expressed no preference.
The values are no-preference, more, less, and custom.
No. prefers-contrast reports a preference; forced-colors reports that the browser is actively overriding author colors.
Common improvements include darker text, thicker borders, clearer underlines, and stronger focus indicators.
No. The default must already be readable and accessible. Preference queries enhance an adequate base.
They ignore the media block and keep the default styles, which is why the defaults must stand on their own.

Next: forced-colors

Detect when the browser forces a limited color palette.

forced-colors tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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