{"id":324247,"date":"2020-10-29T07:51:07","date_gmt":"2020-10-29T14:51:07","guid":{"rendered":"https:\/\/css-tricks.com\/?p=324247"},"modified":"2022-11-22T15:59:07","modified_gmt":"2022-11-22T23:59:07","slug":"the-css-custom-property-toggle-trick","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/the-css-custom-property-toggle-trick\/","title":{"rendered":"The CSS Custom Property Toggle Trick"},"content":{"rendered":"\n

Back in July 2020, I got an email from James0x57 (I always try to refer to people by their name, but I think I get the sense they prefer to go by screen name) that says:<\/p>\n\n\n\n

The entire world of branching conditional logic and bulk feature toggling for custom CSS properties is possible and only exists because of a tiny footnote in the CSS spec that has gone unnoticed.<\/p><\/blockquote>\n\n\n\n

That line<\/a> is:<\/p>\n\n\n\n

Note: While <declaration-value> must represent at least one token, that one token may be whitespace.<\/p><\/blockquote>\n\n\n\n\n\n\n\n

In other words, --foo: ;<\/code> is valid. <\/p>\n\n\n\n

If you’re like me, this doesn’t read as some massive revelation that unlocks huge doors, but to smarter people, like James0x57, it does! We started working on a draft blog post, but for various reasons it didn’t make it all the way here. One of those reasons is that I just wasn’t getting it.<\/em> Call me dense, sorry James0x57. One demo they sent me when I asked for a super dumbed-down example was helpful though, and I think it’s kind of clicked for me. Here’s my interpretation:<\/p>\n\n\n\n