It’s very easy to get CSS to respond to JS. Just change an attribute on the appropriate element and bam.
Being able to listen to a custom property change would let JS respond to CSS.
It’s easy to do a lot quickly in CSS, especially now with container queries, preference queries, and :has. But if your JS state needs to synchronize with that CSS state you’re out of luck and need to move everything into JS where it gets a lot wordier.
For a concrete example I’ve run into more than once: say you have a menu that’s a row of disclosure popups on big screens and a hamburger on small screens.
You can do almost all of this in CSS except for stuff like setting aria-expanded on the buttons. If you’re careful you can keep your JS mostly agnostic of the CSS state but you’re going to need to know about when the transition from/to small/large screen happens just to make sure everything gets reset and focus doesn’t get lost anywhere. That means moving the MQ into the JS to know when the changeover happens even though the JS doesn’t really care why this is happening or at what breakpoint.
It’s not clear how to update this to CQs and without custom MQs this means either duplicating the MQ in the CSS and JS, an additional build step to keep it synched, or putting it in JS and communicating the visual change by toggling a .hamburger
class or somesuch.
It would be much cleaner, imo, if the JS could just listen to some custom prop and let the CSS control when that prop gets updated and why.