The way I write CSS is about to change again


View this email in your browser (or share it with a friend!)

PRE-S: Sending this week’s newsletter out early this week, which I’ll talk about more of why a little further down.


Hello Reader,

I’m so curious about how some of the new CSS features that are coming out now are going to impact how we author our stylesheets in the years to come.

I think the one that might have the biggest singular impact might be the advanced attr() function, which finally allows us to use the values of data attributes anywhere in our CSS.

Beyond that though, we’re getting:

  • mixins
  • functions
  • if statements
  • probably more than I’m forgetting!

At first, these types of things will be used similarly to how we use the same features in pre-processors like Sass, but over time, I can only guess that we will push on from there.

I’m thinking about this because I was thinking back on how I used to use custom properties, and how it's evolved over the years.

Custom properties are essentially variables, and we’ve had them in preprocessors for a long time.

When I first started using them, I treated them in essentially the same way.

Eventually, I realized that locally scoped custom properties were amazing (they’re not as great with pre-processors because of the limitations they have being pre-rendered).

Using locally scoped custom properties changed a lot of how I used them, and I started using many local properties that I could override where needed.

And most recently, I’ve shifted to using a lot of fallback values, like var(--card-font-size, --base-font-size).

This sets the default as the base font size, but it's super easy to overwrite it with a modifier or somewhere specific.

If you'd like to see this approach in action, you can see me go all-out in my Bento Grid video from a few weeks ago.

This evolution of how I’ve been using them has taken years.

I realize others go there before I did, but it’s still one of those things where, unless we have a specific need, there is often no reason to change how we work, so we just keep on doing what we know.

Then, we either see someone else do something new or think of a clever idea and test it out, and slowly but surely, we make some progress in how we might use something.

And with so many new features about to be added to CSS, it’ll be fun to see where things go in the short-term, but also how different things might look after they’ve been stable for a little while as well, and the new patterns and workflows that come from them.

Also, if you'd like to see custom functions and mixins in action, I haven't had a chance to play with them yet, but Dmitry Mayorov has a video looking at each:

One thing I will say is that I know a lot of people worry that this explosion of new features will make CSS more complicated.

In a way, it does, but the nice thing is, they don't change the learning curve.

The basics are still the basics.

There are no breaking changes and new complexities for beginners.

f anything a lot of things are easier for beginners now that we have the correct tools for the jobs we need to do instead of relying on hacks.

There is more to learn, but if you have a strong foundation in the language, adding on top of that foundational knowledge usually isn't too bad 😊.


Speaking of keeping up with modern CSS, the reason why this week’s newsletter is going out a few days earlier is that I want to let you know that Miriam Suzanne is hosting a workshop on CSS Layouts.

The workshop is on building more resilient and maintainable web layouts using modern CSS, covering all the essentials, from block and flexbox to grid, subgrid, container queries, box alignment, and more.

The reason I’m sending this out today instead of Sunday is because there is a $100 early-bird discount running through April 12, and I didn’t want anyone to miss out on it.

This isn’t a sponsored slot or anything, but I know a lot of my audience could benefit from it.

I always love learning from Miriam because she knows CSS layouts at a super deep level (and has even helped write the spec for container queries), but is also able to explain everything in a way we can all understand.

If you’re interested, you can watch a little preview, or get more information and register for the workshop here.

🙋‍♂️ What I’ve been up to this week

How to set a max-column count using Grid auto-fit or auto-fill

video preview

Both auto-fit and auto-fill are amazing, but sometimes they keep making more columns when you don’t want it to keep making more.

Setting a max-width on the grid can work, but I don’t always want to limit that to be too narrow either, so I found a way to set a maximum number of columns!

It does take a little bit of work, but once we have the custom properties set up, it works well and is easy to modify as well.

Here’s the CodePen from the video if you want to poke around with the code.

⚡ Quick tips of the week

🎙️ Podcast

Keeping it simple to overcome procrastination

In this week's episode of General Musings,I talk about how, when I'm struggling to do something, I try to find the easiest path to getting started. It can be hard just diving in, and if something is hard, even if you start, you might not want to continue!

LISTEN ON: APPLE | SPOTIFY | YOUTUBE | WEB

🔗 Other awesome stuff around from the web

🏁

Have a fantastic week!
Kevin


Are you looking to step up your CSS? I've got both free and premium courses to help with that! They cover a range of skill levels too 👇

Beginner friendly (and free)

Conquering Responsive Layout

A free course to help you approach responsive layouts with the right mindset.

Enroll →

Intermediate

CSS Demystified

For those who've been writing CSS for a little bit now, but want to step up their game and start writing CSS with confidence!

Enroll →

Advanced

Beyond CSS

An advanced course that dives into project architecture, theming, design systems, and more.

Enroll →

If you no longer want to get any emails from me, you can unsubscribe or you can edit your preferences if you'd like pick which emails you get from me.
113 Cherry St #92768, Seattle, WA 98104-2205

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, One big problem with features like Grid and Flexbox (and maybe soon Masonry) is that we can move elements around. This might sound like a feature, but in reality, it can cause many issues because even something as simple as flex-direction: row reverse can muck with tab order. There are times where it can potentially be a good idea to re-order things with CSS (say, when you want an image above a title of a card, but in...

CSS Hell

View this email in your browser (or share it with a friend!) Very quickly, before we get into the topics of this week's newsletter, the State of Devs survey is going to be closing shortly. The survey is for devs, but asks about who we are, rather than what we know. As with all the "State of..." surveys, the more people who take it, the more representative the results are, so if you have a few minutes, it'd be great if you could take the time to take it. Hello Reader, So, Figma had a big event...

View this email in your browser (or share it with a friend!) Hello Reader, Have you ever found yourself staring at some CSS that you were sure should work, but it wasn’t doing what you wanted? If so, welcome to the club 😂. These days, for me, it’s less about not understanding a specific behavior and more about making dumb mistakes, but there are times when it still catches me off guard as well. At this stage, most of the time I can reason my way out of the problem I’m facing, but with years...