Skip to content

[css-color-5] Is relative colors "omitted alpha" rule useful? #10991

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

Closed
emilio opened this issue Oct 2, 2024 · 10 comments
Closed

[css-color-5] Is relative colors "omitted alpha" rule useful? #10991

emilio opened this issue Oct 2, 2024 · 10 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-color-5 Color modification

Comments

@emilio
Copy link
Collaborator

emilio commented Oct 2, 2024

https://drafts.csswg.org/css-color-5/#rcs-intro says:

If the alpha value of the relative color is omitted, it defaults to that of the origin color (rather than defaulting to 100%, as it does in the absolute syntax).

That was a bit unexpected to me, and feels it could be for authors as well. Given authors can just type an extra alpha on the color, is it really worth the confusion?

cc @svgeesus @weinig

@emilio emilio added Agenda+ css-color-5 Color modification labels Oct 2, 2024
@svgeesus
Copy link
Contributor

svgeesus commented Oct 2, 2024

@LeaVerou

@LeaVerou
Copy link
Member

LeaVerou commented Oct 2, 2024

Completely agreed, no idea what I was thinking when I wrote that — if I did write that — it’s not part of my original proposal; @tabatkins proposed it later though that was in the context of omitting any value, which was still on the table. Looking at commits it appears that it was you @svgeesus that introduced it?

So I suspect we'll have consensus to remove the rule, the tricky part now is web compat…

@romainmenke
Copy link
Member

There is interop for the current specification and this behavior is well documented: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_colors/Relative_colors#:~:text=Optionally%2C%20an%20alpha%20channel%20value%20for%20the%20output%20color%20can%20be%20defined%2C%20preceded%20by%20a%20slash%20(/).%20If%20the%20alpha%20channel%20value%20is%20not%20explicitly%20specified%2C%20it%20defaults%20to%20the%20alpha%20channel%20value%20of%20the%20origin%2Dcolor%20(not%20100%25%2C%20which%20is%20the%20case%20for%20absolute%20color%20values).

There also is no way to do feature detection for such a change.

Authors could always write an explicit alpha component even for 100% during the transition period. Would take a long time, but relatively speaking, still a short term pain point.

@tabatkins
Copy link
Member

tabatkins commented Oct 2, 2024

Yeah, I argued for the omitted-alpha behavior (and was actually the original contributor; Chris's commit is just rearranging that text), and I still think it's a good idea.

Alpha is the only channel that exists in every single color syntax, with identical meaning. So it's always safe to transfer the alpha like this, in a way that any other channel wouldn't be.

More importantly, it's pretty much independent of the rest of the color. Nearly any meaningful operation you could possibly do to a color will adjust its non-alpha components only, unless the operation is specifically to adjust the alpha. Virtually nothing does both: lighten, darken, saturate, grayscale, sepia, hue shift, they're all alpha-independent. As such, it's easy to forget to handle the alpha when you're working on non-alpha components.

Put another way, almost every single relative color ever written (that's not just doing an alpha modification itself) will want to put / alpha at the end if this is removed. That's silly boilerplate, at that point; it's a minor but persistent footgun that will force people to constantly go "why does this look wrong? oh, duh, it's lost its alpha, gotta put / alpha on it". And it's easy for the mistake to go unnoticed when testing your initial styles since you likely won't think to test with a transparent color; it'll only show up later when you try to use a partially-transparent color in production and annoyingly end up with all your derived colors being fully opaque.

So, no, we won't have consensus to remove it; I feel pretty strongly that the current behavior is a good idea.

@svgeesus
Copy link
Contributor

svgeesus commented Oct 3, 2024

I also feel that the current omitted-alpha behavior is the most useful one. Avoiding having to type / alpha is better than having to type / 1.

@emilio
Copy link
Collaborator Author

emilio commented Oct 3, 2024

To be clear, I don't have a too strong feeling one way or the other. I did find it confusing as an author, and when reviewing code to implement it. But I guess I could see it being useful? It's just a bit "too magic" for my taste. If you accidentally find this behavior and don't want it, it's not super-clear that you need / 1 (where that's the default everywhere else).

@LeaVerou
Copy link
Member

LeaVerou commented Oct 3, 2024

Ok, after reading @tabatkins’s comment, I'm also convinced it’s a good idea 😁

@kbabbitt
Copy link
Collaborator

kbabbitt commented Oct 3, 2024

+1 for preserving origin alpha. The way I think about it is: in relative color syntax, the author is starting with an origin color and then specifying modifications to it. If they don't say anything about a particular aspect of the origin color, it should be left untouched.

@svgeesus
Copy link
Contributor

svgeesus commented Oct 3, 2024

So, @emilio can we close this?

@emilio
Copy link
Collaborator Author

emilio commented Oct 3, 2024

Sure, sounds fine :)

@emilio emilio closed this as completed Oct 3, 2024
@svgeesus svgeesus added Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. and removed Agenda+ labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-color-5 Color modification
Projects
None yet
Development

No branches or pull requests

6 participants