DEV Community

Cover image for In defense of CSS
Silvestar Bistrović
Silvestar Bistrović

Posted on • Originally published at silvestar.codes

In defense of CSS

I am here to take a stand and defend CSS, my most favorite programming language. I don't care if it is a proper programming language or not, and I don't think the authors cared, too. However, I do care about its beauty, power, simplicity, and complexity.

Side note: I asked a question about respecting CSS on Dev.to earlier this year. Unfortunately, the discussion escalated and went in the entirely wrong direction.

If you started to learn CSS in the last couple of years, consider yourself lucky. I have been kind of lucky, too, and I have avoided table layouts, but I had to deal with float layout. Today, CSS is much nicer and friendlier, and you don't need to use too many "hacks." No matter what, I always loved it.


The thing with CSS is that you need it, whether you love it or not. Cascade, stacking context, box models, these could be tough and abstract, but you need these to be your friends, not enemies. It is easy to jump straight to frameworks. Bootstrap, Tailwind, Bulma, whatever, these are great, but it comes down to mastering the basics. I have been the loudest spokesman of Bootstrap for years, but I had to master the CSS basics anyway. Although I rarely use frameworks these days, I am still curious, exploring new and shiny players here and then. There is nothing wrong with broadening your horizons, as long as you know the basics.


CSS is moving fast. New features emerge every year, making our lives both harder and easier. Sometimes a new feature adds more complexity. Take Cascade Layers, for example. It will be hard to master the concept of controlling the cascade. But, sometimes, a new feature provides a more straightforward solution. Take the aspect-ratio property (which is finally supported by all major browsers, btw). It feels so good not to use the padding hack anymore. Whether a feature is complex or not, the important thing is that CSS is moving in the right direction.


Just like you need CSS for web-based projects, you need JavaScript as well. I am not a JavaScript developer, but I use JavaScript daily. I know enough to get by and to avoid mistakes. When es6 was introduced, I was afraid of it. I did not even master the es5, and the new JavaScript version was out. I tried to ignore it, but I could not do it forever. So I had to learn it and understand how and when to use new features. Eventually, it made my life easier, but the learning path was not straightforward.

What I did not do was complain all over the Internet about it. Instead, I got my hands dirty and wrote a tone of code until it made sense to me. I did not expect to do it without spilling blood, sweat, and tears. It doesn't work that way.


Before you decide to write something terrible about CSS, try to understand what is going on first. Mastering CSS is all about understanding the context and concept and everything in between. It is not CSS' fault that you don't know how to use it.

“It is not CSS' fault that you don't know how to use it.”

If you don't write CSS often, you shouldn't be bothered. JavaScript superhero Dan Abramov admits he doesn't know CSS (if you have 5 minutes, you could watch Dan trying to center a div). So please don't rant about CSS if you're not using it regularly. Everything is hard when you don't use it. However, if you use CSS daily, you better start learning CSS and get better at it.

Top comments (4)

Collapse
 
lexlohr profile image
Alex Lohr

The issue most people have with CSS is that they only want the Styles without either having to maintain separate Sheets or letting themselves be confused by the Cascade and its selectors' specificy.

As with many seemingly simple languages, CSS is easy to learn and difficult yet ultimately rewarding to master.

It's a bit like back-end people thrash-talking JavaScript for not being Java. If you criticize something without sufficient knowledge to back your criticism, you'll come across as ignorant, biased and opinionated.

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".

Collapse
 
deathshadow60 profile image
deathshadow60 • Edited

Most of the problem with CSS is people trying to use it without understanding the most basic concepts of HTML. We see the same problem with client-side scripting in that people dive for it before they know enough HTML or CSS to be playing with that yet, or to even know if it's needed.

This is evident in how many of these garbage "frameworks" can't even be bothered to say media="screen" on their LINK tag. Because of course their screen layouts are so worth the bandwidth to send to my braille reader, or to screen readers, or even non-visual UA's like search engines.

Therefor people dive into the mind-numbingly dumbass half-tweet nose-breathing incompetent DISASTERS that are HTML/CSS frameworks. The monuments to the stupidity that are Bootcrap, Failwind, w3.css, YUI, and so forth with their undoing 23 years of progress, pissing on the very reasons HTML and CSS even EXISTS, and are a symptom of the poor education and worse documentation of said languages.

HTML is for saying what things are, grammatically and structurally. Even tags like <B> and <I> exists to say things WOULD be bold or italic when not <em>phasized -- such as a book title not being <cite>d -- or <strong>'s "more emphasis" -- like a entity/party in a legal document -- not that such text has to or should be italic or bold. Thus that MEANING can be conveyed across all UA's, not just browsers.

If you are choosing ANY of your HTML tags based on their default appearance, or using classes / id's that are presentational, you have shoved your cranium up 1997's rectum in terms of methodology. As I've said for ages the difference between:

class="text-center color-500-grey text-large"

And

<center><font color="#777" size="+2">

Amounts to exactly two things. Jack and ****, and Jack left town. It is literally the bleeding edge of 1997 development practices. Made all the more pathetic by how if you dare to talk out against the derpitude, people accuse you of being stuck in the past.

When such ignorant practices are the norm, disrespecting the very reason CSS even exists, it's hardly a shock the rank and file hate it, when it's actually a thousand times simpler than people think.

Folks out there don't learn to use HTML properly, thus they can't learn to use CSS properly, and it cascades down from there into asinine trash like presentational classes, BEM, pre-processors, frameworks, etc, etc, etc,

Thus why the people who CREATE front-end frameworks generally aren't qualified to write a single blasted line of HTML in the first place... as evident for EVERY blasted example people "learn from" in the idiocy that are front-end frameworks. The people MAKING these "alternatives" never learned enough HTML or CSS to build such systems in the first place, which is why they're unqualified to build anything, much less have the unmitigated gall to tell others how to do so.

Collapse
 
__manucodes profile image
manu

!important should be illegal