CSS Reference ยท Media Queries and Features
The prefers-contrast media feature
Reference for the CSS prefers-contrast media feature: detect a request for more or less contrast, the more, less, custom and no-preference values, with examples.
The prefers-contrast media feature tells you whether the user has asked their system for higher or lower contrast between foreground and background. Someone with low vision may want stronger contrast; someone sensitive to glare may want softer contrast. Your styles can adapt: thicker borders, darker text, fewer subtle gray-on-gray combinations.
@media (prefers-contrast: more) { .button { border: 2px solid currentColor; } }
Try it
The card uses a soft, low-contrast style by default. When your system asks for more contrast, the text turns black on white and the border gets thicker.
Syntax
@media (prefers-contrast: no-preference) { /* ... */ } @media (prefers-contrast: more) { /* ... */ } @media (prefers-contrast: less) { /* ... */ } @media (prefers-contrast: custom) { /* ... */ } @media (prefers-contrast) { /* matches when not no-preference */ }
It is a discrete media feature.
Values
| Value | Description |
|---|---|
no-preference |
The user has not expressed a contrast preference. |
more |
The user wants higher contrast. |
less |
The user wants lower contrast. |
custom |
The user chose their own color set (for example a custom palette) that is neither clearly more nor less contrast. |
Usage notes
- Strong defaults first. Your normal design should already meet WCAG contrast guidelines. This feature is an enhancement, not a replacement for accessible colors.
- Do not weaken by default. Only lower contrast inside
lesswhen the user asked for it, and keep text readable. - Borders and outlines.
moreis a good place to add visible borders to elements that rely on faint shadows or background differences. - Different from forced colors.
forced-colorsmeans the browser replaces your palette;prefers-contrastleaves your palette in place and lets you adjust it. - Not every system offers it. Many users never touch this setting, so do not depend on it to make the page usable.
- Pair it with testing. Browser developer tools can emulate the preference.
Browser support
Supported in current versions of the major browsers; check a compatibility table for the exact releases you need.
Related
forced-colorsโ forced palette modeprefers-color-schemeโ light or dark@mediaโ the at-rule- Lessons: Media Queries, Dark Mode