5 ms·
If you're going to use Tailwind why not just use the style attribute and just give up on CSS classes?
by PaulHoule 3y ago
If you're going to use Tailwind why not just use the style attribute and just give up on CSS classes?
- jasmataz 3y agoTo me the biggest reason is selector specificity, especially when it comes to authoring component libraries. Inline styles written with the style attribute are impossible to override without using !important, which only exacerbates the specificity problem.
- 7952 3y agoIt is easier to find how to do things using tailwind documentation than with native CSS documentation. As someone who is not very good at CSS it makes my life easier.
- mierz00 3y agoOne reason is that you can’t do media queries in a style attribute.
- 1123581321 3y agoUtility classes still encapsulate some complexity and responsive styling. They also generate colors from the global palette. Finally, they’re less verbose without losing much meaningful information.
- Rodeoclash 3y agoTailwind does a better job at enforcing a set of standards in the codebase. Specifically around things like spacing, text sizing etc. This doesn't preclude enforcing it directly in the CSS files, but it does make it a lot easier.
- deprecative 3y agoPeople make a bunch of excuses for Tailwind. If you're going to write CSS just write CSS. Stop coping.
- truckerbill 3y ago"If you're going to write assembly just write assembly."
- mcluck 3y agoThe difference is that high level languages actually bring a level of abstraction not present in assembly. Tailwind does not exist on a higher level of abstraction. It's at the same level but written in a different vernacular
- moritzwarhier 3y agoI think the word "coping" is inappropriate here, it's a tradeoff and in addition a matter of preference. You might like not having 24000 permutations of display: flex; align-items: center; in your code. There are good alternatives to Tailwind and also small projects where "just write CSS" is enough. In larger projects, most people need at least strong naming conventions, other tools, and/or an opinionated "template" such as Bootstrap. Many people using Bootstrap don't even bother to configure a theme. That's where the real specificity wars begin then (not necessarily applicable to you). And once people have started to define their design system in terms of overrides, pain is ahead (if you need any non-trivial CSS, that is). After switching jobs, I now mainly use CSS-in-JS (which frees me of many problems, and in my case, creates fewer other problems). I am perfectly versed in Vanilla CSS and the cascade, wrote my first stylesheet around 20 years ago (when layout in CSS was not really a thing) Why is doing things differently from your preference "coping"?
- dbbk 3y agoI would much prefer the explicit, vertically-legible, autocompletable and real CSS rules to a horizontal mishmash of proprietary aliases.
- moritzwarhier 3y agoI'm not even disagreeing with that. I saw the tradeoffs of Tailwind too. And yes, I also agree with the core of your critique: Tailwind is a (yet another) DSL on top of CSS, which makes it smelly. But as I see it, the reason for using Tailwind is not that this DSL was easier, in fact it's the opposite, I constantly had to use IDE autocomplete and/or the docs in order to use it. Tailwind is a nasty DSL inside the class attribute, yes. And still, this DSL can be and often is a relieve from other custom CSS that grows exponentially and causes bugs due to selector complexity. Tailwind IMO solves the same problem that styled-components, CSS Modules and ShadowDOM try to solve.