Compatibility with the proposed CSS if function
Author: stofCreated Jun 19, 2024Updated Dec 18, 2025
LabelsenhancementCSS compatibilityrequires deprecation
- Phase 1
- Phase 2
- Specification
- Tests
- Dart Sass
- Website
The CSSWG has resolved working on inline conditionals for CSS. For now, the proposed syntax uses a if() function.
See https://lea.verou.me/blog/2024/css-conditionals/ and https://github.com/w3c/csswg-drafts/issues/10064
Even though the syntax is not yet final (the proposal has just started), the current syntax will require adjustments in Sass:
- the special
ifSass function (which has a special parsing and evaluation) will need to be distinguished from the CSS conditional - the current proposal uses
if(condition ? then : else)as syntax, which fails to parse in Sass (I'm testing that usingcss-ifas the function name to avoid issues with the first point):- the ternary syntax fails to parse: https://sass-lang.com/playground/#eJwzNExUqOZSUEiyUkguLtbNTNMoSyzS0NVNzs9LySzJzM/TVLBXSMopTVWwUihKTdG05qoFAIT+D1Q=
- the style condition fails to parse inside the condition of the function: https://sass-lang.com/playground/#eJwzNExUqOZSUEiyUkguLtbNTNMoLqnMSdXQ1S1LLLJSSMvP11SwV0jKKU1VsFIoSk3RtOaqBQCRIQ9c (note that this syntax works when storing the condition in a custom property thanks to the fact that custom properties accept any content in Sass, requiring to use interpolation to use SassScript expressions: https://sass-lang.com/playground/#eJwzNExUqOZSUNDVTc7PS8ksyczPs1IoLqnMSS3W0NUtSyyyUkjLz9fkqgUAA7AM4Q==)
The work on this proposal should be tracked to figure out how the compatibility layer should look like.
Source: sass/sass