Have you ever wished the browser would look at a background color and pick black or white for the text — whichever one provides more contrast? Now, the `contrast-color()` function in CSS does just that.

https://webkit.org/blog/16929/contrast-color/

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?

WebKit
@jensimmons Nifty new feature. Also, I was delighted by the in-depth discussion about choosing colors for accessibility. Thanks for calling that out!

@jensimmons Because feedback was requested:

I will not use this until a better contrast calculation algorithm has been implemented. APCA has been shown to be superior in every real-world test I have seen. While I'm happy that you've indicated willingness to replace it later, I would have loved to see more leadership from the Webkit team. Please adopt a superior contrast scoring method (APCA) instead of a demonstrably broken algorithm that is divorced from how we perceive colour and contrast.

@jensimmons This is so cool. Is there any info about where this is in the standards process? I had trouble finding much info about it, so I assume it’s still early days?

@estoner Oh it’s fully specified:
https://www.w3.org/TR/css-color-5/#contrast-color

This version that choses between black/white that is.

CSS Color Module Level 5

@jensimmons Aha! That helps, thank you.

I’m having trouble finding any record of it in places like caniuse and MDN; is it too early for that, or would it be files under something other than “contrast-color”?

@estoner It's not too early to be on MDN / in MDN BCD or in Can I Use. It’s just that no one has added it yet. (Git PR on GitHub to the open source project(s) will do it.)
@jensimmons Would love to see the Messages team show this same interest in contrast ratios, since it's well documented that green texts have an accessibility-unfriendly contrast ratio while blue ones don't, presumably a cynical play to increase the unattractiveness of green texts.
@jensimmons is that first s a typing error?
@mjr Yes. Thanks! And thankfully I can fix it on Mastodon.
@jensimmons Once Upon A Time there was a thing called the "Windows Style Guide" and you didn't have to worry about *any* of this stuff. Buttons were buttons - you asked for a button, you got a button, end of.
@jensimmons Nice! But I think being able to specify custom light/dark text colors is quite important for most use cases… Hope that can be added soon. (I read the discussion about it in the post.)
@jhogervorst Agreed. Especially since many sites use a super light grey or a very dark charcoal black for their “white” and ”black”.