Skip to content

[css-color] color-contrast() should support ranges of candidate colors, not just discrete color candidates #7360

Open
@LeaVerou

Description

@LeaVerou

When designers are picking colors to pass a certain contrast ratio, they usually adjust a given coordinate, in a given color space (usually lightness). The current color-contrast() syntax only allows providing specific candidate colors, so I worry we will see a lot of this:

background: var(--color);
color: color-contrast(var(--color) vs 
	lch(from var(--color) 100% c h),
	lch(from var(--color)  90% c h),
	lch(from var(--color)  80% c h),
	lch(from var(--color)  70% c h),
	lch(from var(--color)  60% c h),
	lch(from var(--color)  50% c h),
	lch(from var(--color)  40% c h),
	lch(from var(--color)  30% c h),
	lch(from var(--color)  20% c h),
	lch(from var(--color)  10% c h),
	lch(from var(--color)   0% c h)
);

It would be good if there was a syntax to provide the candidate colors as a range, either by reusing <gradient>, or with a watered down microsyntax:

  • such as a functional syntax range(<interpolation-method>, <color>#)
    • example: range(in lch, lch(from var(--color) 100% c h), lch(from var(--color) 0% c h)))
  • or a keyword-based syntax like <color> to <color> <interpolation-method>?
    • example: lch(from var(--color) 100% c h) to lch(from var(--color) 0% c h) in lch

The range would be considered ordered, and browsers would return the first color in the range that passes the target contrast (which they may decide to calculate via binary search). It may make things simpler if ranges can only be from one color to another color.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed Deferreda11y-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