The problem with CSS


PRE-S: With my course CSS Demystified about to relaunch, I'm going to be sending a lot more emails than usual. If you'd like, you can stay on my regular Sunday list, but opt-out of the extra emails.

Hello Reader,

I’m sure you’ve seen this before.

Most people use it to poke fun at CSS and use it as an example of one of the many problems with CSS.

The thing is, it’s actually an example of how CSS solves a problem the user created.

Most problems we run into don’t happen because CSS is broken or a bad language. They happen because we’re not approaching CSS with the right mindset.

CSS was created and continues to evolve based on a very important principle: the author of the CSS doesn’t control how the content is displayed, the user does.

This makes it very different from other languages because we have to try and style things without all the information.

We don’t know:

  • What device the user is on
  • The size of their viewport
  • What browser are they using
  • Whether they’re even using a browser
  • Their input device (mouse, keyboard, touch, voice)
  • And the list goes on

CSS was designed for this uncertainty. It’s not a bug, it’s the entire point.

That’s why we have the CSS is Awesome meme. The text is overflowing outside of the box. People laugh and say “there goes CSS being weird again” and point to it as a problem with the language, rather than realizing if that were to happen, it's because they declared a fixed width on the box.

In other words, it would have worked fine, but they wrote CSS that got in the way and caused a problem.

If a user visited a page on their phone and the font size was too big (or there is a long word that's causing a problem), would it be better if the title was cut off and we are missing half the word, or would it be better if there was some overflow and the user could scroll to the side to be able to read it all?

Ideally, the text wouldn’t overflow at all, but if it does, we wrote the CSS that caused it. CSS just tried to work around our mistake.

Our job, when writing CSS (whether that’s regular CSS or using something like Tailwind, or maybe a preprocessor like SCSS), is to consider that someone might be on a small or very big viewport, and write CSS that can adapt to those situations, along with everything in between.

We need to make accommodations in our layouts and styles, not because CSS is broken, but because the web is a medium of unknowns, and CSS is the only language that has to deal with that head-on.

We can’t hard-code things because CSS doesn’t exist in a hard-coded world. It lives in a world of variables we can’t control.

But we can learn to work with it instead of against it. More on that tomorrow.

Cheers,
Kevin

P.S. I’ll be in your inbox quite a bit over the next week or so. If that’s not for you and you’d like to just get my regular Sunday emails, click here to opt out of these extra emails.


Unsubscribe · Preferences
600 1st Ave, Ste 330 PMB 92768, Seattle, WA 98104-2246

Hi! I'm Kevin

Weekly newsletter, where I talk about tangentially-related front-end development topics and share what I've been up to in the last week, plus any cool/fun/interesting/useful links I come across as well.

Read more from Hi! I'm Kevin

View this email in your browser (or share it with a friend!) Hello Reader, Earlier this week, I posted this on Bluesky. I’m not panicking about the talk itself right now, but as I’ve spent time working on my talk this week, imposter syndrome has hit hard. I know for a lot of people, and especially with newer developers, I’m either the person or one of a handful of people they think of when they think of CSS, so it might seem a little crazy for me to be having imposter syndrome, but boy is it...

View this email in your browser (or share it with a friend!) Hello Reader, In the last three days, I’ve created more content than I usually do in one week (and no, don’t worry, I’m not about to try and sell you some productivity system 😆). As I sat down to write this, I wondered what I had done differently to get so much done, and at least some of it was due to a small tweak I made to my workflow on Monday. I won’t bore you with the details, but I want to talk about the idea of removing...

Selfie, standing in front of a canal in Amsterdam

View this email in your browser (or share it with a friend!) Hello Reader, And I’m back from Smashing Conf Amsterdam, where I had an absolutely wonderful time! Amsterdam is such a beautiful city Amsterdam is one of my favourite cities to visit, and Smashing knows how to put on a wonderful conference, so I had high expectations in combining the two, and it didn't disappoint 😊. As for my talk, it went great… and what an amazing venue to speak at! The Pathé Tuschinski theatre As for my talk, the...