DEV Community

Discussion on: In defense of CSS

Collapse
 
sargalias profile image
Spyros Argalias

I agree with your points... At the end of the day, CSS is our only option, so we have to learn how to work properly with it.

However, I still don't really like CSS. It's very unintuitive. It's the worst user experience I've ever had as a developer, even compared to JavaScript. I've had to learn it inside and out to not fall into traps, and I consider myself to know it very well. I consider this a problem with the language, it's not a good thing. Cars should be easy to drive and products should be easy to use. If someone needs to know a car inside and out to be able to drive it, that's bad (functional) design. So I completely disagree with the "you just don't know it well enough" argument. No, that's a design problem of the language itself.

In CSS, many things are unintuitive and have exceptions.

  • width, height, padding and margins can use percentages, but borders can't. Why not? Because it's CSS. I would be very surprised to find out that it was another reason.
  • Margin-collapsing? Not very intuitive. You won't notice it until it bites you. Inconsistent usage within CSS too, with margin-collapsing not working in a flexbox context.
  • Side effects everywhere? overflow: hidden; creates block formatting context, position: absolute creates positioning contexts and block formatting contexts. We only got explicit values for these recently.
  • Responsive images were a hack until recently
  • Vertical centering was a hack until flexbox
  • Line-height and fonts... Not easy.
  • CSS custom properties in media queries? Lol no.

Some non-CSS problems are also:

  • No help from tools to do static analysis (imagine how hard normal programming would be without these tools).
  • Developers don't know how to code CSS well in terms of architecture. E.g. use the cascade where appropriate but scope or BEM otherwise. Using appropriate scope is a requirement in programming, it's not different in CSS. Use classes and not IDs or !important, etc.

I digress. I think CSS could definitely have been better. Things are still unintuitive. But things are improving and moving in the right direction. I believe it's becoming better and I'm slowly starting to consider it "good" rather than just "the best we have" or "our only option".