By: Adam Marostica
Posted: 2025.10.15
In this article, I want to explore how we can use CSS's powerful attribute selectors to manage component states (traditionally handled by JavaScript) directly within our stylesheets.
Why? Because too often, our styling logic ends up living in our JavaScript, wrapped in ternaries, helper functions, and conditional class names. Sure it works, but it also couples behavior and appearance more tightly than it needs to. Moving some of that logic into CSS makes our components simpler, more declarative, and easier to reason about. With a minor shift in mindset, we can get CSS to do more of what it's already great at: styling by state.