CSS custom properties and the cascade | adactio

CSS variables (aka CSS custom properties) do not have access to the cascade. That means they can't fall back to earlier rules, so if your variable is invalid, the browser will simply unset that property. Huh. Jeremy explains the logic behind why this needs to be the case but it's still interesting. I understand that dynamically generated variables should probably work this way, but on initial render I'm still surprised it doesn't hold on to the current cascade value whilst it checks the variable and just fall back to that if the variable is invalid.

But if I store the background colour in a custom property, I can no longer rely on the cascade.

Explore Other Notes

Newer

Pine.blog

Pine is an interesting tool for curating information. It acts as a feed reader, importing content from RSS, Atom, mf2 etc. That means you can subscribe to Tumblogs, YouTube channels, subreddit feeds …

  • <!DOCTYPE html> <html> <head> <title></title> </head> <body> <p>CSS variables (<em>aka</em> CSS custom properties) do not have access to the cascade. That means they can't fall back to earlier rules, so if your variable is invalid, the browser will simply unset …</p> </body> </html>
  • Murray Adcock.
Journal permalink