5 ms·
Utility classes aren't the same as inline styles (2021)
- city41 3y ago> utility classes won’t let you deviate because they’re limited Tailwind's just in time feature does negate this a bit. I'm a huge fan of Tailwind but I've largely avoided JIT for fear of losing the structure finite classes give me. Edit: the down votes are interesting as this is literally what Tailwind JIT allows. Their post on it even says "We’ll likely add some form of “strict mode” in the future for power-hungry team leads who don’t trust their colleagues to use this feature responsibly."
- ramesh31 3y agoNo, they're much worse. Lament for the folks that have to maintain that stuff for years after it saved you 30 seconds of dev time.
- city41 3y agoI know we're just going to have to agree to disagree, but I find utility class based projects easier to maintain. Coming back to -- or inheriting -- css soup is never fun.
- quickthrower2 3y agoI think people compare the best possible CSS with Tailwind rather than comparing what actually gets done with actual Tailwind.
- deleted 3y ago[deleted]
- ramesh31 3y ago> I think people compare the best possible CSS with Tailwind rather than comparing what actually gets done with actual Tailwind. Yep. The one Tailwind guy on the team will set everything up perfectly, and then no one else will ever have any desire to ever learn Tailwind, and it descends into a complete mess. You can say "just learn Tailwind!", and see how far that gets you with a group of backend devs who've inherited some UI and just need to add a button.
- 1shooner 3y agoRegardless of how easy devs find it to be now, there's no denying that utility-only CSS is fighting the platform it's built on. jQuery and SASS showed the way for their specs to build toward. Contrast that to utility-only CSS, which I suspect is just going to get left behind as CSS solves the problems Tailwind, et al. try to work around.
- naasking 3y agoOn the contrary, utility classes actually drive you to HTML components/composing HTML fragments for HTML reuse, thus eliminating duplicate markup. This is a big problem that CSS, SASS, etc. are not solving and probably can't solve.
- hmeh 3y agoInstead of letting our tools lead us by the nose, what if we let design principles lead us? Why would a styling tool lead me to model my markup? That's the complete inverse of how one should be thinking about it. You model the markup first, you create reusable bits if you need them first. Then you style them. If the CSS forces your hand to change the markup, then you must, but that's becoming more and more rare with modern CSS. I have no doubt that people that don't know the fundamentals at play have an easier time with Tailwind. That's how it goes with hacks. They're usually easier to apply than proper design and implementation. We're throwing in the towel with Tailwind, plain and simple.
- naasking 3y ago> You model the markup first, you create reusable bits if you need them first. Agreed, and with Tailwind you never have to leave this fragment of markup you're designing. You don't have to switch files to add CSS and invent meaningful names for styles, then ensure you use the same name in the markup file, nor do you ever have to hunt down and change these names and the markup across multiple files to ensure they are applied consistently down the road of you're using HTML components. In fact, you rarely have to write CSS at all, you just focus on the markup and sprinkle in the predefined styles that you need. Much simpler. > We're throwing in the towel with Tailwind, plain and simple. If by throwing in the towel, you mean we're acknowledging that they took a suboptimal design path, I agree. Transclusion of HTML fragments would have been a much better path to take, and some people were arguing for it even back then (Xanadu folks IIRC). Now we've come full circle, and people are still arguing that decomposition for reuse are not good ways of structuring dynamically changing and evolving content.
- CuriouslyC 3y agoUtility classes give you the immediacy and power of inline styles in a consistent and controllable way, and they're a natural bridge to class based styling. If you've had a bad experience with utility classes, that's because you've had to deal with bad codebases that use them, rather than due to inherent issues.
- 000ooo000 3y agoSounds a lot like the classic "Hate Agile? You just haven't done it properly" rhetoric
- CuriouslyC 3y agoMaybe, if the normal "agile" definition was limited to just stories and a sprint structure of some kind - atomic user stories and short, feature centric development cycles are hard to argue against. If your intention is to liken Tailwind to SuperMegaScrumKanbanJujitsuMarketingCoderStyle agile, I can assure that there is no real similarity.
- 000ooo000 3y agoMy comment has more to do with the No True Scotsman fallacy than it does with Agile
- sensanaty 3y agoI've worked with Tailwind in 3 separate, huge projects, and it's infinitely easier to upkeep than the monstrosity that large SCSS/CSS codebases turn into. There's no hunting down random css classes all over the codebase, no dealing with insane cascade issues, no idiotic specificity issues, no unused classes that everyone is afraid to touch because it might break some random div somewhere...
- pier25 3y agoYou can still write component-based CSS/SCSS without Tailwind and that solves all problems you mentioned
- joshuaturner 3y agoCSS/SCSS modules are still, for me, the best option to balance maintainability and flexibility within a component
- hmeh 3y agoHave you ever tried making your SCSS/CSS codebases not a huge monstrosity? It can be done.
- CipherThrowaway 3y agoI find this criticism interesting. Among the people actually doing it, it seems to be a near universal experience that Tailwind projects are easier to maintain than class based CSS. What is it about Tailwind that is unmaintainable, in your view?
- deleted 3y ago[deleted]
- preommr 3y ago[flagged]
- emi2k01 3y agoThe guys at OpenAI decided to use tailwind to style the boxes in ChatGPT
- ralmidani 3y agoUtility classes which require a build step add complexity and bloat to an already complex and bloated ecosystem. Personally, I am using Bootstrap (without Sass), but even if I wasn’t, I would rather write inline styles or a custom style.css file than have to deal with build systems and, in general, Node/NPM churn and dependency hell. Full disclosure: I am biased toward Django, htmx, and Bootstrap, and avoiding the use of build steps completely. The DX has been amazing.
- CuriouslyC 3y agoDoes it really matter how good your DX is if your stack limits you to making virtual magazines and fancy crud apps?
- aaronbrethorst 3y agoI’m not sure what you’re responding to regarding virtual magazines or fancy CRUD apps, but I’d guess that 99%+ of all web apps built are CRUD apps—fancy or otherwise.
- austhrow743 3y agoWhy would it not?
- lelanthran 3y ago> Does it really matter how good your DX is if your stack limits you to making virtual magazines and fancy crud apps? I'm probably misunderstanding your comment and I think if you elaborate a little it might help. My understanding is that very few sites (or apps) are NOT a fancy CRUD app.
- CuriouslyC 3y agoBy volume, crud apps are the vast majority. They're also one of the least engaging type of work IMO, particularly once you've done a few. Compare writing a crud app with making an immersive game, or an application like photoshop/davinci/etc. I don't know about you but I want to do interesting, deep work and if my stack is holding me back from that, that's a problem.
- interstice 3y ago> Inline styles only apply to the elements they’re declared on This is a feature. Utility classes that do more than 1-2 things are hellish to reason about at scale, especially when they start interacting with each other
- 000ooo000 3y agoThis article is a strawman. No-one who has compared utility classes to inline styles is asserting that they are the same on a technical level, because that is obvious. The argument that utility classes are basically inline styles refers to how both assign style directly to a single element in a way that is not re-usable at a level of abstraction that promotes DRY. If your counter to this is "well those styles are contained in a React/whatever component which makes it DRY", you're making a different argument where the suitability of utility class frameworks relies on coupling with a component framework. To take this article seriously I would need to see a section on the maintenance obligations imposed by utlity classes and inline styles, versus an approach such as semantic CSS. Until then it just looks like "well ackshually they aren't the same". With some strange lofty bits about knowledge.
- naasking 3y ago> If your counter to this is "well those styles are contained in a React/whatever component which makes it DRY", you're making a different argument where the suitability of utility class frameworks relies on coupling with a component framework. It does not require any such framework, although those frameworks can use the same approach. PHP and Perl were composing DRY HTML fragments even before JavaScript or CSS were invented. That this is possible and straightforward does not require more than the 30+ years of evidence that already exists. But if you want more, here's a simple one: CSS promotes DRY of CSS markup at the cost of repeating HTML markup. Do you have more HTML or CSS in any given project?
- hmeh 3y agoIt's not about DRY. It's about modeling. It's about design. It's about being able to look at markup (as a human) and tell what the heck it is. Tailwind soup obscures what things are. How many of your Tailwind-using apps ALSO have meaningful class names and IDs in your markup? How many of you rely on data-test-id or other such hacks to make up for the fact that you are not doing design. Classes are used to categorize the markup. It's a document model. Model the document. Then, you apply styles to that. It's about design.
- hmeh 3y agoSure, Tailwind isn't inline styles. Fine. That doesn't make it good. And yes, most CSS is average or below average in implementation. Most software is too. That's just statistics. Tailwind is an attempt to prevent people from recognizing that, like software, CSS requires design and modeling. It's perfectly possible to have a CSS system that is completely maintainable. It takes skill. That skill can be learned, but it cannot be learned if a person is tricked into relying on rapid-application-development tooling like Tailwind and not taking the time to understand the real problems with their CSS (which is very often special cause variation and/or not taking it seriously enough). Tailwind doesn't solve anything, it just trades one bad thing (poorly written CSS) for another. I won't list the problems with Tailwind as that's been done plenty. I'm just pointing out the fundamental mistake here. My experience: The first version of our app used React + Tailwind. When we started to ditch React and use server rendered HTML our React components and their embedded Tailwind were useless. When we wanted to share styles with our emails, they were useless. We had to start from scratch. We now have a plain CSS system (well, SASS) that is very well maintained, has only essential variation, and is used across 20+ web apps (that are all served on the same domain -- the user thinks they are one app).
- kaba0 3y ago> It's perfectly possible to have a CSS system that is completely maintainable. It takes skill Yeah, and people wrote complex games in assembly. The difference is maintainability and if it can be done by more than one people. CSS doesn’t scale across teams/dependencies in its vanilla form in my experience, not at all. It is “spooky action at a distance” almost by definition, often with no way to even control/revert what some deep dependency does.
- hmeh 3y ago> CSS doesn’t scale across teams/dependencies in its vanilla form in my experience, not at all. In your experience. It was my experience too, until it wasn't. See this: https://news.ycombinator.com/item?id=39501442 https://news.ycombinator.com/item?id=39501442 > often with no way to even control/revert what some deep dependency does Without looking at specifics, it is hard to say, but it is very likely that this is a design mistake. It's very likely that the person making these mistakes is also making these mistakes in code and creating tangled messes there. The state of development is quite poor. "Average" (read: most) developers create tangled messes because it's all they know how to do and they've never taken the time to learn how not to do it. So, when something like Tailwind comes along and says "you can't make a mess with this", then of course they will jump on it. They will not, however, be very interested in recognizing the costs that come along with it. They also will be incapable of seeing that the other path is not only simpler, but it can become easier with practice.
- kijin 3y agoIt depends. OP's utility classes look too much like inline styles, with colons in the class names and whatnot. I can easily imagine a new developer seeing that, scratching their head, and wondering "wait, I can write CSS inside the `class` attribute?" Tailwind is much more restrained in comparison.
- NoPedantsThanks 3y ago[dead]
- jgalt212 3y agoutility classes are like coding in assembly language. there's often a 1:1 mapping to machine code (actual css), and almost always just too little abstraction for my taste.