> All in One 586: Maybe don’t use custom properties in shorthand properties

Ads

Thursday, March 6, 2025

Maybe don’t use custom properties in shorthand properties

Manuel Matuzović:

That an invalid custom property invalidates the entire declaration isn’t surprising, but I didn’t consider it until I saw one of my declarations break. I guess it’s just good to know that, especially if you’re working a lot with custom properties.

This easily qualifies as a “gotcha” in CSS and is a good reminder that the cascade doesn’t know everything all at the same time. If a custom property is invalid, the cascade won’t ignore it, and it gets evaluated, which invalidates the declaration. And if we set an invalid custom property on a shorthand property that combines several constituent properties — like how background and animation are both shorthand for a bunch of other properties — then the entire declaration becomes invalid, including all of the implied constituents. No bueno indeed.

What to do, then?

So, maybe don’t use custom properties in shorthand properties or use custom properties but don’t use shorthand properties.

Great advice, Manuel!


Maybe don’t use custom properties in shorthand properties originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.



from CSS-Tricks https://ift.tt/AwDeX8y
via IFTTT

No comments:

Post a Comment

Maybe don’t use custom properties in shorthand properties

Manuel Matuzović : That an invalid custom property invalidates the entire declaration isn’t surprising, but I didn’t consider it until I s...