brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: @media (prefers-contrast: more) in CSS adds contrast for people who ask for it

Css
~/tips/tip-css-prefers-contrast-more

@media (prefers-contrast: more) {

Soft grey text and faint borders get stronger when the system setting asks for more contrast.

Pale grey text and hairline borders look calm, but they are hard to read for a lot of people. Operating systems have a setting to ask for more contrast, and CSS can read it.

.meta { color: #6e7781; }
.card { border: 1px solid #d0d7de; }

@media (prefers-contrast: more) {
  .meta { color: #1f2328; }
  .card { border: 2px solid #1f2328; }
  a { text-decoration-thickness: 2px; }
}

The media feature matches when the user turned on something like Increase contrast on macOS and iOS. Inside it I’d darken secondary text, make borders thicker and darker, and remove see-through backgrounds that make text hard to read.

There is also prefers-contrast: less for people who find strong contrast tiring, and custom, which MDN links to forced colors mode with a palette that is neither clearly high nor low.

Support is good: Chrome 96, Firefox 101 and Safari 14.1. You can test it without changing your system settings through the Rendering panel in Chrome DevTools.

A caveat worth keeping in mind: this is an extra, not a fix. Your default colors should already meet normal contrast guidelines, since many people who struggle with low contrast never touch the setting.

Further reading: MDN: prefers-contrast

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link