-
Notifications
You must be signed in to change notification settings - Fork 690
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
[css-color-5] color-contrast() needs resolution logic if 2 or more have the same contrast #4732
Comments
Good catch, @argyleink I agree this needs to be specified Given that the second parameter to
We also need to specify what happens if the first param is not a valid color, or any item of the second param are not valid colors.
|
Yeah, since there's no further context to decide ties, going with first-wins seems reasonable. |
Not so fast on the closing, Chris :)
|
Note that these all give the same contrast of 6.08, when rounded to 3 significant figures as your tool does, @LeaVerou but when a higher precision is used, purple wins. I made that point in the spec text. |
first wins, i dig it. |
The algorithm is given in WCAG 2.1 and the inputs are the relative luminances of the two colors being compared. In utilities.js I have added that function, for convenience, although the inputs are sRGB only (same as WCAG):
I also have a Notice that relative luminance is just the And even for calibrated spaces like CMYK etc, if a color profile is provided. It is always just a case of computing two luminances, Y1 and Y2, then doing the simple ratio (with 5% flare compensation). Luminance has been defined by an international standard since 1931, we don't need to define it in CSS just document how it is calculated, to help developers. |
I should probably add another contrast example where the color list includes display-p3, prophoto-rgb, and lab and lch values. |
feels like there's clear resolution on this issue, it's ready to close yeah? |
|
Both of those cases are "doesn't match the grammar" and thus are invalid, right? |
Yes, I assumed so. Or, if a custom property is involved and the parser can't tell, invalid at computed value time. Do we need t say either of those things explicitly or is it just assumed? |
They're just assumed. If you write something into a property that takes |
OK in that case this can indeed be closed. |
Spec draft
https://drafts.csswg.org/css-color-5/#colorcontrast
Example
verify contrast scores: [hsl(200 83% 23%), purple, var(--purple-in-hsl)]
Given
purple
,hsl(200 83% 23%)
, &hsl(300 100% 25%)
all have the same contrast with--bg
, which wins? First match, cascade, your idea?The text was updated successfully, but these errors were encountered: