Description
The relative color syntax in level 5 allows existing colors to be modified using the color functions. For example, we can start with a base color green
, and manipulate it in lch
space, by performing calculations on the l
, c
, and h
channels:
/* example from the spec */
html { --color: green; }
.foo {
--darker-accent: lch(from var(--color) calc(l / 2) c h);
}
This syntax predates the specification of missing color components in level 4, represented by the none
keyword. While the addition of none
to the function syntax has been ported into level 5, it's not clear how this should interact with the relative color syntax.
What should happen when the base color has a missing component, and the relative syntax performs a calculation on that channel?
html { --color: lch(0.5 0.5 none); }
.foo {
--complement: lch(from var(--color) l c calc(h + 180deg));
}
I see three basic options:
-
Invalid operation. This seems like the 'default' if we don't specify something different, since
none
is clearly not a valid number forcalc()
. However, I think it's not a very useful behavior, and we should avoid it if possible. In general, it seems bad to say 'some valid colors will simply break if you adjust them' - especially sincenone
can result from internal CSS operations. -
Calculate with
0
in place ofnone
. This may be the most obvious choice, since it matches the behavior in other cases where we need a number value fornone
. But the results aren't necessarily useful, especially when the channel is truly powerless. -
The result is always
none
. This was proposed by @nex3 as it maintains the intent ofnone
to represent powerless or unimportant channels. Rotating a missing/powerless hue results in a hue that is still missing/powerless.
I'd propose that we go with option 3, but I could see arguments for the other approaches. Thoughts?