Support CSS variables
See original GitHub issueCSS Variables introduces the <any-value>
production, and Sass should support it.
This production introduces some serious questions about how Sass should parse it. It’s general enough to allow practically any string, which means that treating it as a normal property would break CSS compatibility. For example, var-foo: 1 +;
is valid CSS, but currently Sass would fail to parse it. Fundamentally, we need to decide what balance to strike between compatibility, programmability, and user expectations. Here are several options:
- The most compatible option would be to parse it exactly as specified in CSS and make no changes. For example,
var-foo: $var
would emitvar-foo: $var
literally, without replacing$var
with its Sass value. This would make it impossible to assign variable values programmatically, though, as well as seriously violating user expectations. - The most programmable option and the option that would be least surprising to users would be to parse these as any other property. This would be a much larger break with CSS compatibility than we’ve done before, though, which itself violates the user’s expectation that all CSS is valid SCSS.
- We could meet somewhere in the middle by allowing the use of
#{}
and possibly a single variable in<any-value>
productions. This violates both compatibility, since$var
is a valid CSS value that a user’s JavaScript might theoretically use, and user expectations, since e.g.var-foo: $var1, $var2, $var3
won’t work as expected. However, it will support most valid CSS and will allow variables to be created with mixins, albeit possibly with an ugly intermediate variable. - We could try to parse the value as a plain SassScript value, and if it fails to parse treat it as an unparsed. This would mean that any syntax errors would be difficult to track down, and poses more serious compatibility issues than option 3, since
var-foo: 1 + 2
will be treated very differently in Sass than in raw CSS.
I’m not sure what the best option is. If I had to choose now, I’d probably lean towards option 3, but I don’t really like any of them.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:3
- Comments:39 (12 by maintainers)
Top Results From Across the Web
CSS Variables (Custom Properties) | Can I use... Support ...
CSS Variables (Custom Properties). - CR. Permits the declaration and usage of cascading variables in stylesheets. Usage % of. all users, all tracked ......
Read more >Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >Browser Compatibility of CSS Variables (Custom Properties)
CSS Variables (Custom Properties) on Chrome is fully supported on 49-106, partially supported on None of the versions, and not supported on 4-48 ......
Read more >A user's guide to CSS variables – Increment: Frontend
CSS variables are currently supported for 93 percent of users globally. CSS variables are currently supported for 93 percent of users globally. If...
Read more >CSS Variables - The var() function
The var() function is used to insert the value of a CSS variable. CSS variables have access to the DOM, which means that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Guys, this should be top priority thing. Since you’re declaring full CSS compatibility you’re lying already. Moreover, since Polymer 1.0 uses custom CSS mixins, it doesn’t seem to be possible to write in SCSS at all:
Code above whould be compiled to exactly the same thing. It seems that check for
--
prefix should be simple enough to implement, and if--
prefix found - leave it as is on current level.I’ve read briefly all the above and still miss 1 use case. What if developer creates a SASS mixin to be used inside of SASS, but then will want to export that to be used outside (as CSS mixin). Ideally that would look like:
Sadly, none of the above would work, while this would be used a lot (I was actually in need of such thing myself). Any ideas if that will be possible and eventually when?