Get the latest tech news

How to have the browser pick a contrasting color in CSS


Have you ever wished you could write simple CSS to declare a color, and then have the browser figure out whether black or white should be paired with that color?

In fact, if you try out our demo in Safari Technology Preview now (as this article is published in May 2025), you’ll find many of the pairings with mid-tone background colors don’t result in enough contrast. These recommendations can really help guide designers to select the size and weight of text to ensure enough contrast, while allowing a range of beautiful color combinations. Because a decision on which color-contrast algorithm to use for WCAG 3 is still being debated, the CSS Working Group decided to move forward with a tool that simply chooses black or white to contrast with the first color.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of browser

browser

Photo of css

css

Photo of contrasting color

contrasting color

Related news:

News photo

Smalltalk-78 Xerox NoteTaker in-browser emulator

News photo

Show HN: Sam TTS – Recreates the classic Microsoft SAM voice in the browser

News photo

Show HN: Translate between dialects and share SQL queries on the browser