Skip to content

[css-color-4] no contrast guarantee due to wrong threshold #1632

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

Closed
xi opened this issue Jul 20, 2017 · 1 comment
Closed

[css-color-4] no contrast guarantee due to wrong threshold #1632

xi opened this issue Jul 20, 2017 · 1 comment

Comments

@xi
Copy link

xi commented Jul 20, 2017

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

The definition of the contrast adjuster says that if the base color has a luminance smaller than 0.5, maximum-contrast color should be white, otherwise black. In order to gurantee sufficient contrast, the threshold of 0.5 should be much smaller, somewhere between 0.1833 and 0.175.

Further explanaition:

The contrast ratio is calulated as (L1 + 0.05) / (L2 + 0.05) where L1 is the larger of the two luminances, and L2 is the smaller. Luminance is between 0 and 1.

To find the highest luminance that still has sufficient contrast with white, we can solve the following formular for L: (1 + 0.05) / (L + 0.05) = 4.5 => L = (1 + 0.05) / 4.5 - 0.05 ~= 0.1833.

To find the lowest luminance that still has sufficient contrast with black, we can solve the following formular for L: (L + 0.05) / (0 + 0.05) = 4.5 => L = (0 + 0.05) * 4.5 - 0.05 = 0.175.

Note that luminances between these two values offer sufficient contrast to both black and white.

To find the luminance that has the same contrast with both black and white, we can solve the following formular to L: (1 + 0.05) / (L + 0.05) = (L + 0.05) / (0 + 0.05) => L = sqrt((1 + 0.05) * (0 + 0.05)) - 0.05 ~= 0.1791.

Here is an example of a color with luminance very close to 0.5: https://leaverou.github.io/contrast-ratio/#rgb%280%2C%20218%2C%2039%29-on-white

@svgeesus
Copy link
Contributor

Closing since the contrast adjuster is no longer part of the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants