Live data from Hacker News

Tailwind is a leaky abstraction

jakelazaroff.com

121–130 of 391 posts

Re: Tailwind is a leaky abstraction

#121
post #33
post #6

Tailwind has made building components in React an absolute joy for me. I don't need to scroll up to find my css-in-js definitions, I don't need to change windows to find the CSS modules, it's all there, in one place.

After trying out Tailwind in one pet project I have to say that for larger teams it should not be used. Looking at the code now I get the feeling that maintenance would be a big problem. A bigger project with multiple pages having full on Tailwind css classes peppered everywhere looks to be a nightmare. Does anyone have experience jumping into an existing larger project with legacy tailwind all over the place? Would…

I've had some experience migrating large UI projects at work to use a design system based on Tailwind. Haven't faced any issue with Tailwind at all, even while integrating in existing projects.

Tailwind is a different way of writing CSS, with some guard-rails coming in from the design system consistency. Tailwind also provides sane defaults (rem over px, for instance).

If someone's bad at writing or thinking in CSS, chances are, they'd be bad at Tailwind too.

I've found Tailwind helps me focus on writing the CSS that matters. But just having Tailwind CSS in a project won't automagically fill one's gap in CSS knowledge.

This isn't bootstrap, where one can use some col-* utilities and magically get a grid layout that just works across browsers.

Tailwind is a bit lower level, and to achieve similar responsive layout, you still have to know how to do that with CSS grid, what the breakpoints are etc.

Where Tailwind aids here, is by providing utility classes that help with original CSS grid intuition. For instance, `grid-cols-2 sm:grid-cols-4 md:grid-cols-6` would be hard to achieve by hand, writing vanilla CSS or styled-components.

> A bigger project with multiple pages having full on Tailwind css classes peppered everywhere looks to be a nightmare.

Ideally, you would be using a framework to help organize code better. Most likely React or Vue or something similar.

In which case, you'd already have components.

There are more than one way to achieve same look and feel, with CSS. Similarly, one can apply some discipline with using Tailwind's utility classes, when building anything.

Two heuristics that have worked for me, are:

- Never use margin if you can, use flex-box and grid with gaps instead. Placing a children node is parent's responsibility.

- Write symmetric CSS. Prefer px over pl or pr, mx over ml or mr etc.

Using margins make it hard to extract some React markup as a reusable component. Using symmetric CSS gives you automatic RTL compliance without using any of the CSS logical properties.

Sure, there'd be times when a UI design cannot be implemented without breaking some of these. But in most cases I've encountered at work, building consistent UIs, have been easy for me and my team following these.

Happy to go into details with code examples, if anyone's interested.

Re: Tailwind is a leaky abstraction

#122

I haven't actually used tailwind yet. But writing CSS -- usually with SCSS, sometimes bootstrap, sometimes just totally DIY -- I have _never_ managed to keep my CSS well organized. It always eventually becomes an unholy spaghetti mess, including overrides of overrides. So my interest in tailwind or "utility" approach generally (I have started using bootstrap utility classes more), is not to avoid having to know CSS,…

Tailwind really shines for this, but the caveat seems to be that it's much more useful when using a component-based frontend framework (React, Svelte, Vue, Angular, etc.) I was recommending it to a friend who does wordpress development, but it occurred to me that it might not be useful (or not as useful anyway) in that environment. For React, all the alternatives I've used have really sucked.

I used Tailwind v1 to build a WP theme years ago. It was still useful to enforce the design system and color tokens. With the Block Editor, I imagine that's even more true now. The hardest part is customizing all of the different modules/plugins to either use TW classes (via injection somewhere) or write a custom CSS file with `@apply` rules.

The WP theme templating system has partial file includes, so creating "components" is certainly possible.

Re: Tailwind is a leaky abstraction

#123
post #108
post #47

These are fairly complex use-cases that aren't needed for 99.9% of CSS people write. In most cases I'm throwing together a handful of components in a flex container or right-aligning some buttons or something. And for that typical CSS usecase, I find Tailwind way better both for quickly iterating and for hopping into code someone else wrote. I love not having to bounce between and cross-reference 2 (or more!) files (…

> I love not having to bounce between and cross-reference 2 (or more!) files (HTML + CSS) for a description of a single layout. Oh wow. Literally this is the exact argument I use for not using tailwind - not having my styling logic split between classes in my HTML and tailwind’s own files implementing the styles (which appears in DevTools and most other places). Not saying either of us is right or wrong it’s just odd…

How does Tailwind require bouncing between multiple files? Everything is in the HTML in the form of class names.

Yes, you will have to know what the classes do, but where that isn't already intuitive it's just a one-off lookup, and then you know.

HTML + CSS can simply not be parsed without hoping between multiple files. Unless you inline all of your CSS, of course.

Re: Tailwind is a leaky abstraction

#124
post #54

Earlier quoted context omitted.

Other than being shorter, what's the benefit of Tailwind over style attributes on HTML tags? (I am no frontender, though I was a "full stack developer" up to CSS 2.0)

> what's the benefit of Tailwind over style attributes on HTML tags For example, you can't specify hover, focus etc. style attributes. You can't specify screen sizes either. Plus there are few Tailwind classes that cover several attributes. Plus many of those styles are just unwieldy. For example, `drop-shadow` is `filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.1)) drop-shadow(0 1px 1px rgb(0 0 0 / 0.06));`

This. The secret super power in Tailwind is editing the tailwind.config.js and forcing standards. Then you have have something like only having four padding options per your style guide and them defined in one specific place. In style tags you could use a CSS var for this as well but you better hope you used it everywhere. Plus, that becomes super wordy: 'padding-left: var(--padding-1)' vs 'pl-1'

Re: Tailwind is a leaky abstraction

#125
post #119

> But that's kind of the point. Tailwind is a layer on top of CSS, but it doesn't actually hide any complexity in the layer below. You still need to know CSS. This completely misses the point of Tailwind. The point is not to hide the complexity of CSS, but to provide access from the markup to enough of capabilities of CSS that you don't have to edit your stylesheets 95% of the time, when you alter the styling of a do…

Maybe I'm going out of a limb here, but wasn't the whole point of CSS to not have to touch the markup when changing the styling? Not trying to talk Tailwind down, I have just missed a lot of the evolution of web design in the past 15 or so years.

Yes. Tailwind inverts that axiom to great effect. It's leaky on purpose.

Re: Tailwind is a leaky abstraction

#126
So far I've found it very nice to work with as shorthand. The only issue I have so far is override scenarios for merging 2 class attributes as it isn't straightforward how this works unless you have a map ahead of time to remove class names that you want overridden.

Re: Tailwind is a leaky abstraction

#127
post #107

Tailwind is awesome for those who don't know much CSS or dislike to work with CSS directly, or it is great for teams, that are not able to define general rules. If you know CSS, you have huge problem to use a tool like Tailwind, cause you always feel like "how does this save me work?" it doesn't.

This really hits why I've bounced off of Tailwind. I've largely been a backend/infra developer but for some reason CSS has always resonated with me; it makes a ton of sense to me and with HTML (or these days, a React or Svelte component) open in one pane and a SCSS file in the other, the purported benefits of Tailwind just don't exist for me.

I get why other people like it and I'll go with it flow when other people have started a project with it, but I feel much less productive when I have to go remember its syntax and behaviors instead of...CSS.

Re: Tailwind is a leaky abstraction

#128
post #47

These are fairly complex use-cases that aren't needed for 99.9% of CSS people write. In most cases I'm throwing together a handful of components in a flex container or right-aligning some buttons or something. And for that typical CSS usecase, I find Tailwind way better both for quickly iterating and for hopping into code someone else wrote. I love not having to bounce between and cross-reference 2 (or more!) files (…

Tailwind is honestly great for beginners since it "simplifies" CSS into short-hand classes. The people that know CSS don't want to learn new classnames when they can use CSS and that is a standard.

I'm personally scared of forgetting CSS if I use Tailwind extensively. I also don't like the aesthetic of all the classnames being bunched together, but Tailwind does have value.

Re: Tailwind is a leaky abstraction

#129
post #25

For inline CSS, I love Styled-System [1] for css as props. My components die and get redesigned too frequently to care for anything else. So I prefer them encapsulated in the Component itself. I find css-as-props is better than a huge string of classes, as it much more readable and statically analyzable. I wonder if anyone is working on a successor to styled-system (though it works fine). [1] https://styled-system.co…

I've been working on a fork of a project that uses styled recently, and I'm pretty sure it's responsible for slowing down VS Code to the point of being unusable, though I don't understand why.

I'll take tailwind over Styled any day

Re: Tailwind is a leaky abstraction

#130

Tailwind is not an abstraction that makes CSS easier. You still have to know all the CSS. The benefit is it makes writing CSS faster. Writing CSS in the markup just makes more sense. People say that markup and style should be separate to adhere to "separation of concerns". But in fact, markup and style should be coupled, because they both pertain to the UI, visuals, and aesthetics.

> necessarily coupled

As a counter: I see a lot of bad markup ordering when you turn off stylesheets or use a TUI browser. You should be laying out your markup in a logical sense (within some reason) where it's easy to parse without styles and navigate with a keyboard—decoupled from styles. CSS grid and the `order` property let us easily move around elements for visual ordering and that this can (and likely should) happen shows that the data layer (HTML) has separate concerns from the visual presentation layer (CSS). Yes I want my first button tabbed to in your modal to be the primary action button even when it is displayed to the right of the cancel button and that's a heck of a lot easier to order it ‘correctly’ and style it in a different order for aesthetics or better visual parsing.

Post reply on HN