← The Log
Web dev

CSS gets an if() function for conditional styling

Chrome 137, which reached stable in late May 2025, added the CSS if() function. It lets a stylesheet choose a value based on a condition, checking a custom property, a media query, or feature support, and returning the first match. Work that used to require JavaScript or a preprocessor like Sass can now live in one line of plain CSS.

In practice this means things like light and dark variants, or a component that restyles itself based on a setting, can be expressed directly where the value is used, instead of scattered across separate rules.

For a small or mid-size business, this is a behind-the-scenes efficiency, not a feature you'll see. It's early, so support is still landing in Firefox and Safari and your developer will keep a fallback for now. But it points the same direction as recent CSS work: less JavaScript, fewer moving parts, and pages that load faster and break less often. Worth a mention next time your site is due for maintenance.

Further reading: original source ↗

Want this handled for you?

This is exactly the kind of thing our website development work takes off your plate. Start with a free, no-pressure look at your site.

Come aboard
Get the Log by email

Plain-English notes on web, marketing, and getting found online. Occasional, no spam.