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, Looks like I’ll be in Amsterdam a lot this year! First, I’m heading there in less than a month from now for Smashing Conf, where I’m giving a talk and an in-person workshop (I've got a link with a discount below if you are able to make it). And, if you can’t make it to that, I’m happy to announce I’ll be back in Amsterdam in June for CSS Day! I’m so excited to be going back to CSS Day again. Speaking there in 2024 was...

View this email in your browser (or share it with a friend!) Hello Reader, If you only have 10 or so minutes of free time for this email, instead of reading it, I’m going to ask that you either read this article or watch this video by Salma Alam-Naylor, where she explores her current thoughts on the tech industry and the impact AI is having on it. I’ve had a lot of thoughts on the current state of things circling around my head without being able to wrangle them in any coherent way, which she...

View this email in your browser (or share it with a friend!) Hello Reader, On Saturday morning, I passed 1 million subscribers on YouTube. I created my channel over 9 years ago. Around 5 months in, I hit 100 subscribers, and at the time, I was blown away that so many people liked my videos enough to bother subscribing. Three years later, I'd passed 100,000 subscribers, which I honestly didn't think was possible for a channel dedicated to vanilla HTML & CSS. And now it's one million. For a...