Skip to content

contrast-color() #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 13, 2024
Merged

Conversation

romainmenke
Copy link
Member

@romainmenke romainmenke commented Jan 1, 2024

https://drafts.csswg.org/css-color-5/#contrast-color

contrast-color( <color> max )

The max keyword indicates that the most contrasting color should be returned. Either white or black.

Omitting that keyword is allowed in the specification but it is purposefully left vague what the behavior should be in that case. This leaves room for browser engines to experiment with this.

I don't want to muddy the waters by providing a polyfill.
If our users want to use contrast-color() without max then they should get the real behavior so that they can also give feedback to browsers.

Another reason not to implement this, is because I would like to tweak the outcome a bit depending on the matching prefers-contrast media query. That can only be done in a PostCSS plugin, not in the color parser package.


UAs are advised to not simply use the WCAG 2.1 section 1.4.3 Contrast (Minimum) contrast ratio algorithm to decide between light and dark colors, as it has several known issues. However, colors returned by this function should still meet the WCAG 2.1 section 1.4.3 Contrast (Minimum) for AA large text, as many authors need to meet legal requirements that mandate this.

This is tricky because there currently isn't anything better.
There are many candidates but there isn't consensus.
Things like APCA are really promising but we really cannot use that because of the attached license.

So for now we are stuck with WCAG 2.1

@romainmenke

This comment was marked as resolved.

@romainmenke romainmenke marked this pull request as ready for review March 9, 2024 17:17
@romainmenke romainmenke merged commit fb253e7 into main Mar 13, 2024
@romainmenke romainmenke deleted the contrast-color--adaptable-wallaby-4b3b3a2615 branch March 13, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant