-
Notifications
You must be signed in to change notification settings - Fork 682
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-4] L as <percentage>
in lab()
and oklab()
#6761
Comments
I'm not sure I understand what you're finding confusing/inconsistent. If anything, having L use percentages to refer to the range of the component in both cases seems vastly more consistent than forcing authors to remember that L in one case is 0-1 and in another, seemingly identical, case is 0-100 (and in a third case is a 0%-100% range) Note that %s referring to a 0-1 range is not consistent thruout the color syntaxes. In rgb(), for example, it covers a 0-255 range. %s are just doing what they're supposed to do - express fractions of a contextually-relevant maximum value (or suitable "unit" value) - same as everywhere else in CSS (and outside of CSS) that uses %s. I'd be strongly against losing the ability to use %s for such an obvious "0 to max" range case. I wish we could use them in the a/b/chroma channels too! |
Thanks for this perspective. I guess(?) I was fixated on percentages resolve to 0.0 .. 1.0 except that for lab the first percentage resolves to 0.0 to 100.0 and overestimated the impact of this "lab exception", whereas in With this interpretation of |
Here, let me help. A color has the following color coordinates (say I found these in some other program and want to use them in CSS)
So I have to remember that CSS treats CIE Lightness as a percentage, and that percentages in CIE Lightness map to 0-100 in CSS so okay I slap on a percent sign; but I just use the numbers as-is
Now I want to use the OK values so I remember that in CSS (as currently specified) I have to slap on a percent and also multiply by 100
Edit: I actually forgot to do this when typing the example
and then I do the OKLCH an, um, does Chroma get multiplied by 100 too? Does it get a percent? If so, that is a percent of what? Wait should I be scaling
Currently, for CSS Color 4 the last of those is correct. The chance that people mess this up in one way or another and end up with an off-by-100 error when simply copying colors into CSS is large. |
The way to fix this on the CSS side is (and always had been) to require units for all components in all predefined color notations (e.g. For the lower-level |
I think you're vastly overcomplicating the mental model people will be using here! I suspect the overwhelming majority of authors will just go "0% lightness is black, 100% lightness is white, values between are colors of varying lightness levels", because that's how lightness already works in HSL, which is the color function closest to Lab/etc that's been in use for decades (and it accords with how percentages work everywhere else in CSS and generally in non-CSS contexts too). You appear to be asserting that it's simpler for authors to remember "in HSL lightness is 0%-100%, in Lab/LCH lightness is 0-100, in oklab/oklch lightness is 0-1", despite all three assigning identical meanings to the endpoints? Like, I get it that if you're copying colors straight from some other application it would be nice to just be able to paste them into the parentheses unchanged, but to assert that this is a simpler mental model seems frankly untenable to me. (I think it's weird that Lab used a rough 0-100 range for the past 50 years while OKLab, intended as a successor which is more or less indistinguishable in most cases, chose to instead scale its numbers to a rough 0-1 range, but hey, I didn't design it. I guess it's just an annoying quirk authors will have to learn.)
I mean, it's not unreasonable for people to assume that chroma, like HSL's saturation, is written as a percentage, but in practice it doesn't have a useful max value as a range. Unfortunate, but that's how it is. It's just an oddity of colors that authors will have to learn; it's a syntax error if they screw it up so at least it's immediately obvious a mistake has been made, and it'll show up as an error in devtools. But yeah, it's already gonna be confusing that lch()'s chroma maxes out in the vicinity of 100 while oklch()'s chroma maxes out in the vicinity of 1. I don't see how the rest of your questions are even remotely believable as an author's thought pattern, so I won't address them. |
As a point of experience, though no real thought out opinion, when implementing support for OKLab in WebKit this week, this bit me briefly (all the resulting colors were very extremely white) and needed to add a divide by 100. The only real downside of using a percentage here in my mind is if it trips users up when pasting in component values from another tool (say, something like https://colorjs.io/apps/convert/?color=lime&precision=4 which uses the unit notation). One concrete thing you might want to consider is updating the sample code to call out this difference. |
I literally just made that mistake (again) when adding the section on resolving OKLab and OKLCH values.
Yes, this is exactly my concern
That tool can be and should be updated, because it primarily tracks CSS and other Web Platform rather than color in general. But other tools will present OKLab values as defined in the OKLab specification which frankly should not surprise anyone.
Good idea. |
We do already have
|
I expect to further clarify this aspect once #6741 is resolved (assiming we resolve to add the reference percentage ranges) |
Noting that i Just fixed Minor typo in css-color-4 example 6 which was caused by a percentage on Chroma ( added here) although in that example it was 0 so the scaling was unclear. |
In addition to the clarified spec prose, the sample code now has, for OKLab: return multiplyMatrices(LMStoOKLab, LMS.map(c => Math.cbrt(c)));
// L in range [0,1]. For use in CSS, multiply by 100 and add a percent and for CIE Lab: return [
(116 * f[1]) - 16, // L
500 * (f[0] - f[1]), // a
200 * (f[1] - f[2]) // b
];
// L in range [0,100]. For use in CSS, add a percent |
In the context of adding
oklab()
andoklch()
syntaxes, which use<percentage>
for the L channel that maps to its canonical[0, 1]
range, the decision to use<percentage>
for the L inlab()
andlch()
(previously discussed) to map to its canonical[0, 100]
range feels inconsistent.Since the spec has recently included a breaking change in the definition of
color(xyz)
, now might be a good opportunity to revisit the decision to use<percentage>
inlab()
andlch()
? (Safari 15 being the only major browser to have shipped all these things.)The decision also impacts the usage of
color()
if these color spaces will be allowed as identifiers, since you're allowed to use either<number>
or<percentage>
for the Lightness channel.I think the simplest way forward is to let
l
,a
, andb
inlab()
andoklab()
all be<number>
s on their own scale. Authors already have to consult reference materials for the useful range of a/b/chroma for each theoretically-unbounded color space, so the L as percentage abstraction doesn't do much to ease that, while making interop with non-web applications (if not the Color API) less straightforward.I don't think consistency with
hsl()
in regards to lightness being a percentage is worth breaking the<number> = <percentage> / 100
convention present throughout the other color syntaxes.The text was updated successfully, but these errors were encountered: