Description
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))
)
- example:
- 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
- example:
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
Type
Projects
Status