Skip to content

[css-color-6] color-contrast() should take transparency into account #7358

@LeaVerou

Description

@LeaVerou

In the current draft, transparency is ignored when calculating contrast, because it was ignored in WCAG 2.1 as there were no non-opaque colors then.

However, this could result in completely incorrect results.

Consider this example: color-contrast(white vs rgb(0 0 0 / .1), gray). Because transparency is ignored, it would pick rgb(0 0 0 / .1) as most contrasting, which produces this result:

image

whereas picking gray would have produced this much more legible result:

image

At the very least, UAs should perform alpha blending of background and foreground (see #7359 ). This would be sufficient when the background is opaque, but it does not solve the problem when the background is also semi-transparent. Ideally, UAs would calculate a range of contrasts and a color would be deemed a winner IFF the minimum possible contrast also passes the desired level (I did some work on calculating said range in WCAG 2.1 10 years ago, not sure if there's a better method these days)

(Issue filed following breakout discussions between @svgeesus, @fantasai, @argyleink and myself)


Resolutions

Aug 2, 2022

  • RESOLVED: When calculating color contrast between pairs of semi transparent colors, if the background is opaque, UAs should alpha blend the foreground on the background and use that as the foreground color. If the background is also semi-transparent, it would be alpha blended first with an opaque version of the foreground
  • RESOLVED: Amend previous resolution, the canvas color in previous resolution is TBD
  • RESOLVED: (rather than opaque version of foreground)

Metadata

Metadata

Assignees

No one assigned

    Labels

    a11y-trackerGroup bringing to attention of a11y, or tracked by the a11y Group but not needing response.css-color-6

    Type

    No type

    Projects

    Status

    Tuesday

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions