CSS Doesn't Need More Power — It Needs Better Boundaries
Also available in Español The Problem A team hits a styling problem that CSS won't cooperate with. Something needs to change based on a click, a scroll position, a piece of application state. So they reach for more power. A heavier selector. An !important . Sometimes CSS gets skipped entirely — element.style.display = 'none' , set directly from a click handler, because it felt more reliable than…
The CSS coding standard has been facing problems that cannot be solved by giving it more power. Instead, the focus should be on better defining boundaries. As CSS has its own inherent authority over presentation, transition, layout, and rendering, it should not be responsible for application state or business logic. The issue arises when CSS crosses the boundary into these areas, breaking the guarantee it already holds.
For example, toggling a panel's display property can be done either directly from a click handler or by using CSS to toggle a class. The second approach keeps presentation completely visible in the stylesheet, making it easier to understand without having to delve into JavaScript. This principle should be applied across the board, with CSS owning presentation, JavaScript managing behavior, and HTML handling structure.
By establishing these boundaries, the unpredictability, entropy, and reliance on JavaScript for presentation logic can be mitigated.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.