Between the braces
In a post called Side Effects in CSS that he wrote a while back, Philip Walton talks about different kinds of challenges in writing CSS:
There are two types of problems in CSS: cosmetic problems and architectural problems.
The cosmetic problems are solved by making something look the way you want it to. The architectural problems are trickier because they have more long-term effects — maintainability, modularity, encapsulation; all that tricky stuff. Philip goes on to say:
If I had to choose between hiring an amazing designer who could replicate even the most complicated visual challenges easily in code and someone who understood the nuances of predictable and maintainable CSS, I’d choose the latter in a heartbeat.
This resonates with something I noticed a while back while I was doing some code reviews. Most of the time when I’m analysing CSS and trying to figure out how “good” it is — and I know that’s very subjective — I’m concerned with what’s on the outside of the curly braces.
The stuff inside the curly braces — the properties and values — that’s where the cosmetic problems get solved. It’s also the stuff that you can look up; I certainly don’t try to store all possible CSS properties and values in my head. It’s also easy to evaluate: Does it make the thing look like you want it to look? Yes? Good. It works.
The stuff outside the curly braces — the selectors — that’s harder to judge. It needs to be evaluated with lots of “what ifs”: What if this selects something you didn’t intend to? What if the markup changes? What if someone else writes some CSS that negates this?
I find it fascinating that most of the innovation in CSS from the browser makers and standards bodies arrives in the form of new properties and values — flexbox, grid, shapes, viewport units, and so on. Meanwhile there’s a whole other world of problems to be solved outside the curly braces. There’s not much that the browser makers or standards bodies can do to help us there. I think that’s why most of the really interesting ideas and thoughts around CSS in recent years have focused on that challenge.
This was originally posted on my own site.