Back to all features
Open for signals
CSS
if()
The if() CSS function is an inline conditional value that returns a value based on a set of conditions.
Community use cases (4)
Community signal summary
Developers strongly support the inline CSS
if()function to enable clean conditional styling without relying on JavaScript [1][3]. Primary use cases include dynamic theme switching across more than two color schemes wherelight-dark()is insufficient [4], toggling property values based on custom state flags [2], and adjusting typography metrics (such asfont-weightandletter-spacing) dynamically according to contextual variables like image dimensions [3]. An engineer at HubSpot noted that lacking conditional expressions forces design compromises, leaving extreme container sizes with suboptimal typography [3].To achieve conditional logic today, developers resort to brittle "space toggle" variable hacks that exploit invalid variable substitution fallbacks [2] or wrapped
@containerstyle queries [4]. However, these workarounds incur significant maintenance penalties; for instance, relying on@containerqueries forces JavaScript style generators to emit complete CSS declaration blocks rather than composable, inline property expressions [4]. Platform sentiment is overwhelmingly positive, with developers seeking nativeif()to eliminate complex CSS hacks, improve design token modularity, and support script-restricted environments [1][2][4].Generated by AI from community comments and may contain inaccuracies. Read the comments below for full developer context.
This summary covers all 4 comments, is up to date, and was last updated on September 5, 2026.
What I want to do with this feature
make elements dependable (if x happens, let y) etc. I want to be able to not use javascript as some websites dont allow it. i use firefox.
What I'm having to do in the meantime
i have to do different things. i cant do any of what i want. i wanted to have two elements dependable and there's no other way to do it properly.
What I want to do with this feature
Make some colors change depending on a flag. The flag can be set in several different ways, so I need to make it a custom property.
What I'm having to do in the meantime
What I want to do with this feature
I have some places where typography scales based on the selected size of the image next to it. I know the size of the image as a variable already, I'd love to be able to set weight, letter-spacing, etc. based on the image size.
What I'm having to do in the meantime
I opted to just pick values that are a happy medium, so the styles look a bit weird at the more extreme image sizes. I could use JS but I'd prefer a CSS-only solution!
What I want to do with this feature
Modulate component styling according to app color scheme. (There are four schemes available, not two, so
light-dark()cannot apply :3)What I'm having to do in the meantime
Use a
@containerquery. This works! It's not ideal because I generate the style within a function, similar tomkSkeuo()below. Using@containermeans thatmkSkeuo()is forced to return a full CSS declaration, making it substantially less flexible than if it were to return anif()expression instead.