This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.
Thoughts on Atomic/Utility CSS
The article <a href="https://frontstuff.io/in-defense-of-utility-first-css" author="Sarah Dayan" source="Frontstuff" date="January 15th, 2018">In Defense of Utility-First CSS</a> is very long<fn>, so I've summarized a bit with notes and thoughts.<fn> I don't really care about being pedantic without first knowing some facts. What are the requirements? <h>Requirements</h> <ul> Can I quickly make a precise change to a single component? Can I make a global, thematic change? How quickly can I make changes? How maintainable is the result? </ul> If atomic/utility CSS can deliver these things, then it's probably a fine tool. But---spoiler alert---it seems more like a tool for designers---not programmers. Programmers have other, better tools for building CSS in a way that fulfills the requirements above. <h>Designers vs. Programmers</h> Essentially, these designers are like we programmers used to be: we used to care about cascading when we were still hand-coding our CSS. Now that we're using LESS or another generator, we can use variables and functions for theming and use local CSS for precision. We can lean on specificity when it suits us and avoid it when it only gets in the way. We want to declaratively say how we want everything to look and let our tools (LESS, WebPack with plugins) figure out how best to generate the CSS to accommodate supported browsers and also to create the kind of CSS that performs well without blowing up memory client-side. None of these optimizations and accommodations for targets should be up to the programmer/designer/CSS-writer at this point. <h>Utility vs. BEM</h> Utility-CSS feels functional, but it also feels like something you use when you don't have LESS. I've never used BEM and agree that it never really made sense, from several good coding practices like DRY. That the author is coming from BEM to utility-CSS is not a surprise: BEM was never a good idea. <h>A Refactoring Use Case</h> <bq>Early refactors are a pretty good indicator of unmaintainability.</bq> I don't agree. It's more a sign of shifting priorities or requirements. It's not uncommon in agile development. The example the author has of changing the meaning of a "card" after there are already components using that style just means that you should make a "card2" class (not a "card-no-ribbon" one) because it's just a different card type. The problem is that the design now includes two cards, not that your implementation should somehow be able to easily roll with a confusing design. Where I see a problem is when a card is supposed to have a certain padding and a border with a certain color (let's say the "padding-top-8" and "border-bottom-lemon" from the author's example). But then you don't want those anymore. Granted, with proper components, you'll only have to change the style in one place anyway, right? So it doesn't matter what you call it. You could have just called it "card" in the local styles and been done with it. So, either you have to remove those highly specific styles in many places in your HTML (as with an old-style web site, like earthli) or you change it in one place anyway (new-fangled, with React components). <h>Visuals vs. Semantics</h> I guess it's the difference between knowing from the HTML what the component is going to <i>look like</i> (<c>
</c>) and knowing what the component <i>is</i> (<c></c>). The author writes: <bq>Yet, the bigger and the more complex a component gets, the less obvious it is to know what class name maps to what element on the screen, or what it looks like.</bq> But then they include an example where it's absolutely clear which components do what: <code><h2 class="entry-title">The Shining</h2></code> I think this again shows the difference between programmers and designers: the code above is crystal clear to a programmer, so if a programmer is writing the CSS, then there's no need to change anything. The author seems to be a designer hell-bent on knowing exactly what the page will look like without actually showing it in a browser. I wish they'd included the version with utility CSS ... it would have been a giant block of unreadable code, doubled in size with class names. <h>Don't Change Anything</h> The author makes a good case for theming using CSS variables, which can be applied "at runtime" in the browser. The solution to theming with utility CSS turns out to be ... making semantic styles instead of precisely named styles. So...not utility CSS. The author references a few other articles, one of which is <a href="http://www.zeldman.com/2017/01/03/kiss-my-classname/" author="Jeffrey Zeldman">Kiss My Classname</a>, which eloquently argues that there is nothing to change. He instead argues that developers and designers should use a <i>visual style guide</i>. <bq>I donít believe the problem is the principle of semantic markup or the cascade in CSS. I believe the problem is a dozen people working on something without talking to each other. Slapping a visually named class on every item in your markup may indeed make your HTML easier to understand for a future developer who takes over without talking to you, especially if you donít document your work and create a style guide. But making things easier for yourself and other developers is not your job. <b>And if you want to make things easier for yourself and other developers, talk to them, and create a style guide or pattern library.</b></bq> <bq>The present is always compromised, always rushed. We muddle through with half the information we need, praised for our speed and faulted when we stop to contemplate or even breathe. (Emphasis added.)</bq> <hr> <ft>It's also almost two years old, but still seems to describe the state-of-the-nation in utility/atomic CSS.</ft> <ft>Another article they referenced was <a href="https://adamwathan.me/css-utility-classes-and-separation-of-concerns/" author="Adam Wathan" date="August 7th, 2017">CSS Utility Classes and "Separation of Concerns"</a> and it's even longer. It's almost a jeremiad with the seeming intent of breaking the reader down with a flood of words. I could only skim it, but it seems like these people are styling without programming: that is, some of the utility classes and even the slightly semantic ones they use could very easily be written more cleanly if they just used component-local styles. For example, this is completely unnecessary with local styles, because you don't have to worry about specificity biting you in the ass: <code></code> In another article <a href="https://css-tricks.com/growing-popularity-atomic-css/" author="Ollie Williams" date="November 24th, 2017">On the Growing Popularity of Atomic CSS</a>, the author mentions that they're addressing <iq>n a mixed-ability team, perhaps involving backend developers with limited interest and knowledge of CSS</iq>. I didn't have the energy to finish that one either, because a skim indicated that it repeated a lot of what was in the article I did read.</ft><h2 class="media-card__title">Stubbing ...</h2> <p class="media-card__body"> In this quick blog post and screencast, ... </p>