My question is why CSS Variables needed to add the concept of fallback and doesn't just rely on inheritance like the other CSS properties.
For example:
:root {
--color1: red;
}
body {
color: var(--color1);
}
body p {
color: var(--color2);
--color2: blue;
}
body span {
--color3: green;
color: var(--color3);
color: yellow;
color: var(--color4);
}
<body>
Text 1
<p>
Text 2
</p>
<span>
Text 3
</span>
</body>
Text 3 ends up in being red instead of green or yellow. Although there are valid properties on the level, it takes the parent color value, instead of verifying if there are other valid values on the same level. This happens when the variable name is invalid.
Apparently there is a special fallback for CSS variables so you need to use something like:
color: var(--color4, yellow);
But this means again duplication of the color, since
color: var(--color4, --color3);
does not work. Neither is:
color: var(--color3, yellow, blue);
or any other multiple values.
Also no support for keywords like inherit, currentColor, initial, etc. So I'm not sure how I could rely on the inheritance since apparently I need to be very explicit with the given values. Tested on Firefox 57.0.1 and Chrome 63.
I know the CSS variables are still as Working Draft so maybe that's why the current behavior.