Hello Reader,
Before we get into this week's content, about an hour before this email was scheduled to be sent, I realized I scheduled it wrong 😅. This one was supposed to go out last week, and I'd already written up another email for this week.
So, sorry for missing last weeks email! The What I've been up to this week section has more than usual, since it covers the last couple of weeks.
One thing I’m a big fan of is writing robust CSS, but one thing with my approach is that it comes with a tradeoff, where sometimes readability can take a little bit of a hit.
Here’s what I mean. Some patterns look a little intimidating at first glance if you haven't seen them before.
Now, this is also a pretty tame example, and you may not find it hard to read, but when I show examples like this on my YouTube channel, I get pushback from some people saying that readability must trump everything, and because they don’t immediately get this, they think I’m over-engineering things.
I disagree, because once it’s written, you don’t read it very often. You use it.
I get the pushback because if you need to update some code and you come across something that’s unfamiliar and hard to understand, it can be a pain in the butt… but again, the purpose here is to write code that doesn’t need to be updated.
Add the class, and you get a responsive grid that works with any number of items, with no media queries. Need wider columns somewhere? Change one custom property, and you’re done.
The alternative is usually a handful of simpler classes, each one easy to read, plus a modifier for every situation. Every individual piece is more readable, but the whole thing is harder to use and more fragile. You can use something in the wrong spot, or you can accidentally add two modifiers that conflict with one another.
A good-quality pattern gets written once, maybe tweaked a couple of times, and then used hundreds of times. So I’d rather make it great for those hundreds of uses.
That isn’t an excuse for clever code nobody can follow. If the next person can’t figure out what something does, that can be a real problem. Comments help, and well-named custom properties also go a very long way.
Most of the time you can have both. When you can’t, I lean toward usability.
A more extreme example is this whimsical button I put together a little while ago.
I had to do a fair bit to get this to work, but I exposed every control someone might want through custom properties. We can control the size, color, starting offset, and ending offset of every decoration on there with a bunch of custom properties that I have at the top of the selector. There’s no need to go and touch anything else in there.
This isn’t the type of component that you’d find in most projects, but I think it does a nice job of illustrating what I’m talking about.
You build something that can handle different situations and is easily customized through some exposed custom props, and then if someone needs to dive into the complexity below, they can, but 99% of the time, there’s no need.
This is top of mind for me right now because it drives the mindset behind the new module I’m working on for CSS Demystified, Writing Resilient CSS. It’s all about writing CSS that keeps working wherever you use it, and it’ll be added to CSS Demystified later this week! (If you already have CSS Demystified, it'll show up in the course automatically).
🙋♂️ What I’ve been up to this week
🎙️ Where do we draw the line with AI-written content?
I shared an article on Bluesky, and a reader flagged it as being AI-generated. Then the author explained how he wrote it, and it got me thinking a bit about the gray zone of AI-generated content.
📺 Use new CSS without breaking anything
As you probably know, I like to talk about new CSS features, but that leads to a lot of questions about browser support, so in this one I look at what Baseline is, why it's useful, and its limitations, as well as how we can use features that don't have perfect support.
📺 Adapt the layout to the number of children
A gallery that picks its own number of columns based on how many items are in it, with no modifier classes and no JavaScript.
🎙️ An AI startup cloned me without permission
I got an email from someone saying that they’d cloned me, and it got me thinking about why people build things nobody asked for, whether AI really changed that, and why you should ask someone outside your idea before you build it.
|
🔗 Other awesome stuff from around the web
|
📝 Quiz time!
An element uses animation-timeline: view(). Which animation-range keyword makes the animation finish just as the element is fully on screen?
As usual, you'll have to head on over to YouTube to take a stab at the quiz, and once you answer, you'll see if you were right or not.
|
|
🏁
Have a fantastic week!
Kevin