CSS variables containing only whitespace are incorrectly removed
See original GitHub issueEnvironment
Just testing at https://clean-css.github.io/
Input CSS
.inset {
--inset: inset;
}
.outset {
--inset: ;
}
.shadow {
box-shadow: var(--inset) 0 2px 2px #0004;
}
Actual output CSS
.inset{--inset:inset}.shadow{box-shadow:var(--inset) 0 2px 2px #0004}
Expected output CSS
.inset{--inset:inset}.outset{--inset: ;}.shadow{box-shadow:var(--inset) 0 2px 2px #0004}
Explanation
Whitespace is a valid value for a CSS variable, like this:
--my-var: ;
This is semantically not the same as:
--my-var:;
From CSS Custom Properties for Cascading Variables Module Level 1:
Note: While <declaration-value> must represent at least one token, that one token may be whitespace. This implies that --foo: ; is valid, and the corresponding var(–foo) call would have a single space as its substitution value, but --foo:; is invalid.
Because of this issue, clean-css currently cannot be used with Tailwind CSS, as we rely on this feature a lot to support class composition in the framework.
Thanks for your awesome work on this lib ❤️
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
white-space - CSS: Cascading Style Sheets - MDN Web Docs
The white-space CSS property sets how white space inside an element is handled.
Read more >White space around css3 scale
How can I remove the withe space around the div while scaled ? I can use js if needed ! EDIT: Here is...
Read more >CSS Custom Properties for Cascading Variables Module ...
If a declaration, once all var() functions are substituted in, contains only a CSS-wide keyword (and possibly whitespace), its value is ...
Read more >Fighting the Space Between Inline Block Elements
Remove the spaces · Negative margin · Skip the closing tag · Set the font size to zero · Just float them instead...
Read more >[OutSystems UI Web Style Guide Preview] Remove hard- ...
... Remove hard-coded values of css variables from colors, typography, spaces, ... as it is based on theme, but ALL IT'D harded-code values...
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
Thanks @adamwathan for more details on this.
@SuyashJoshi179 go ahead with fixing it, that’s much appreciated!
I think you need to fix the tokenizer first as it doesn’t understand that spaces can be significant. Then level 1 optimizations default to whitespace removal for variables, but in this case it should skip if variable’s value is just whitespace.
Hth, let us know if you need anything else.
Hey @SuyashJoshi179! Semicolon is not required you’re correct, here’s a demo:
https://jsfiddle.net/cgys45af/
To test this issue in general, change line 5 to remove the whitespace, then notice that the demo breaks 👍