Skip to content

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

@xi

Description

@xi

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions