Hacker News new | ask | show | jobs
by dpacmittal 1547 days ago
This is the reason I love tailwind. There's no bloat, no headache of naming conflicts (in fact they completely did away with naming), no orphan css. CSS for a full blown website can be less than 5kb. It takes away the pain of thinking about CSS architecture, naming things, conflicts etc and you can just focus on styling.
4 comments

I did not expect to like tailwind, and it still irks my past-self's approach to CSS. But I can't argue that as a wholistic approach to CSS, it is very capable and once you learn the lexicon, very fast to develop with. I really did enjoy it.
Tailwind goes against all old CSS best practices, so I was strongly against it. But I eventually tried it after reading everyone recommending it and it’s great.
It's also one of the very few frameworks that cares about accessibility by default in their examples: no buttons-as-links, no divs-as-lists, clear contrast everywhere.
We have to have Tailwind because we got CSS instead of DSSSL.
Any system using PurgeCSS (like Tailwind) would have the same bloat removed right? (minus the bloat Tailwind adds to your HTML)

Is there a replacement for CSS Modules' "composes" keyword? Tailwind has @apply, but that defeats the purpose of a utility framework somewhat.

I'm a huge fain of Tailwind but if you're using react you can also consider styled-system:

https://styled-system.com

It seems to have a lot of the benefits of Tailwind but better integration with Typescript.

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.

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?