With the introduction of css vars, I would like to know the reasoning of of why --
would be chosen as a way of denoting a var.
Considering CSS has a semi capable calc
function, I feel like the --
could easily be confused for a decrement operator in other languages.
I am curious if there is any historical significance or technical limitation that led to choosing --
. The double in particular perplexes me, when CSS markers are generally singles (#, ., @, etc). Also using a symbol already being used by other things also is interesting (especially when its valid for a class name to begin with --
).
Example:
@custom-media --lt-sm (width < 576px);
--grey300: #e0e0e0;
.navbarItem {
display: inline-block;
text-align: center;
border-top: 1px solid var(--grey300);
border-left: 1px solid var(--grey300);
@media (--lt-sm) {
flex-grow: 1;
}
&:last-child {
border-right: 1px solid var(--grey300);
}
}
Disclaimer
Some might argue the validity of this question, but understanding the why is a key technique to remembering a particular concept.
The only discussion I can find related to it:
In the telcon today, we resolved to use a "--" prefix to indicate custom properties and other custom things.
We discussed whether the prefix is maintained or dropped when referring to the custom property from a var() function, but didn't actually resolve. Discussion in the call leaned toward dropping the prefix, like I do currently with var-* properties, but some side discussion with Simon and Sylvain argued for using the full name, as there are confusing cases like "--0" or "----".
So, while I understand the potential confusion caused by authors possibly thinking that var() can take any property name as an argument, I think it's overruled by the confusion over what needs to be escaped in various circumstances. Escaping rules are always very confusing to authors, so I'm going to go with "use the custom property name literally as the var() argument".
Reference:
http://lists.w3.org/Archives/Public/www-style/2014Mar/0467.html