Hacker News new | ask | show | jobs
by dotancohen 1547 days ago
Tell us a bit more about Tailwind. Last I looked at it a few years ago it seemed a conglomeration of antipatterns. Quick googling is not convincing.

Assume that I know _nothing_ about Tailwind, sell it to me. I'd appreciate it. Thanks.

7 comments

Been developing websites and apps since the days when we are worrying about the y2k bug. Tailwind is my favorite thing. Almost everything that I disliked about CSS is solved by it. Once you really kick the tires, you become way more productive:

Naming is hard. No more naming.

Switching between your markup and your CSS added friction to your flow. No more friction.

Avoiding problems caused by overly aggressive rules / cascade/ whatever is mostly a thing of the past.

I could go on, but if it’s not obvious, I absolutely love it. And the Tailwind UI project is 100% money we’ll spent, too.

I feel the same way about Tailwind, but haven't taken the plunge on Tailwind UI. Though I kinda want to buy it just to support the team. Do you feel like it constrains you too much, or no?
> Though I kinda want to buy it just to support the team.

That's kind but they have earned shedloads already (over $2m USD as of Jan 2021 [1]). That's on top of the $2.3m for the Refactoring UI ebook [2].

1. https://www.smalltechbusiness.com/monetizing-open-source-tai...

2. https://twitter.com/adamwathan/status/1289702466754211842

Ha, fair enough. Though now I'm aware of the book and kinda want to buy it :p
I don’t use anything other than the design ideas. When I’m building a feature, the first thing I do is find a design pattern from Tailwind UI. For that, it’s been well worth the few hundred bucks.
Makes CSS faster to write in the short term, and harder to read in the long term. Also makes complex markup abysmally dense and unwieldy. I understand why people like it but I avoid it when I can. As a Svelte user, my markup is sacred and each component has an automatically scoped style tag so Tailwind is an anti-pattern in any non-trivial project.
> Assume that I know _nothing_ about Tailwind, sell it to me. I'd appreciate it. Thanks.

Tailwind removes (or wilfully ignores) the "cascading" from css. It breaks all good, old css design patterns on purpose - in favor of "widget-level" styling.

It also effectivly builds its own (extendable) style language via named classes, ending up somewhere between "semantic" and "micro-styling" - but allowing for refactoring as needed. It reduces CSS to an implementation detail.

For example, in "Agile Web Development With Rails 7"[1], a number of form fields are initially styled as:

   ... class="block   shadow   rounded-md   border   border-green-400
       outline-none  px-3   py-2   mt-2   w-full " 
Later reactored to:

  ... class="input-field" via tailwind:


     .input-field {  @apply 

         block   shadow   rounded-md  
        border   border-green-400   outline-none 
         px-3   py-2   mt-2   w-full 

    }
On the surface similar to defining a css class - but effectively scoped to your own code.

In a small project, where you're publishing documents - tailwind might not be great - but in a large project, with many widgets it is a good fit.

Similar to how "movable code" (js on the client) might be a better fit than REST for web applications (as opposed to web pages).

[1] https://pragprog.com/titles/rails7/agile-web-development-wit...

The author of Tailwind wrote a blog post explaining his rationale just after the very first version was released: https://adamwathan.me/css-utility-classes-and-separation-of-...

It may be a longer read than you were looking for, in which case I’d say just try it on a small project next time you get the chance. It looks like it wouldn’t work, but it really does.

Aside from was being said, for me, at least when developing component based app, it the better choice IMHO, most css classes contains just one css rule, so you when reading your component class already can visualize how the component looks like. If you are developing a old school web, I would say it could be a pain if you mid project want to change the style of one element (because you are not using components) you need to find and replace every occurrence of the elements classes.

Also not to mention, you skip all the nonsense of the CSS in JS and the need of tools to extract the CSS from JS. Also other big win is that you can use with other projects not based on JS, I'm toying with a WASM app and use tailwind without issues, just run the tailwind bin on my app change (takes a second or less to generate the css file), the only downside here is the need of nodejs (you might be able to download the binary directly and run that, like I do on CI).

I hated the idea of Tailwind when I first saw it. Decided on a whim last year to give it a solid try after hearing others say "you just have to experience it for yourself". I tried it, and now it's literally painful going back to anything else. I can't explain it, it's just magical.

In my opinion, Tailwind is to CSS what jQuery was to Javascript. It's just the right level of abstraction that you need.

But you have to just try it for yourself and experience it. I'd recommend using it with VSCode's intellisense plugin.

Since you use the term "antipattern," what is the respectable pattern (methodology) that Tailwind stands opposed to?
Semantic classes.
How is a class with a single rule, that does exactly what it's supposed to, not "semantic?" What do you think "semantic" means, in this context?

Maybe you mean classes organized with a high level of abstraction that have multiple rules and are meant to be related to the document structure in a specific way?

They might mean a system like BEM, where they are semantic in that they represent concepts tightly coupled to the HTML and what it's used for.

    <div class="product">
        <button class="product__add-to-cart">
        ...etc
BEM is a good example of what Tailwind is a counterpoint to.
Nothing stops you from layering BEM on top of tailwind via @apply - although I'm not sure if that's a good idea. Maybe if creating a full, custom, design-system using tailwind?
Although the Tailwind author hates @apply and says they shouldn't have put it in the tailwind in the first place (mainly because it's a hard feature to develop - i wouldn't be surprised it would be removed). I think going tailwind only is bad too because you loose many of the nice functions of CSS like theming/cascade.

So i think using utility classes/tailwind for base/layout and still using named classes where it makes sense (like common reusable components, hover hiearchies, transitions/animations) is most practical approach. And using BEM as convention for the named classes is not a bad idea - certainly better than no system.

I would say that'd be a Tailwind anti-pattern, since Tailwind exceeds by trying to do away with cascading, and BEM is an attempt to componentize CSS but retain some cascading.

Also, if you handed me a project with that approach, I would run for the hills! How would you decide when to use BEM styling and when to use the tailwind classes? It'd be a nightmare.