We're seeing get quite some traction, so I figured it was about time to try to understand what sets it apart and what problem it solves.

I think I get it now, and to solidify my understanding, I'm going to try to articulate its benefits.

To understand Tailwind, you need to understand constraint-based design, in which UI elements adhere to a set of constraints designed to make them compose well together to make a harmonious whole.

To go down this rabbit hole, see: styled-system.com/guides/why-p

Show thread

This idea isn't unique to Tailwind. Component libraries like Chakra UI and Material-UI apply it already.

However, to enable the sharing of constraints across your app, these libraries define their styles in JavaScript, using tooling to prevent them from interfering with yours.

This leads to inflated bundle sizes and complex tooling.

Show thread
Follow

So how about we just define the constraints in, say, CSS variables?

Well, you could do that, but consider how you would use those.

You'd keep switching between your components and your styles, defining new classes in your CSS that rely on the constraints, and then applying these classes in your components. It adds a layer of indirection between the styles and the components to apply them to.

This layer of indirection was intended to allow you to re-use your classes in different HTML elements.

But in the age of component-based architecture, is that still useful? We write our HTML once for our components, and then re-use those components across our codebase.

Show thread

Tailwind does away with that indirection: you apply your design constraints directly in the component, using plain CSS. It provides "utility classes" like p-0 to p-9, to apply a little to a lot of padding, respectively, to an element. Whatever you choose, it'll be consistent.

Show thread

So to recap, the advantages:

- Constraints keep your design consistent.
- Simple tooling, with just few kBs shipped to your users.
- Styles defined in the context of the component to which they apply.

And to address the elephant in the room: yes, this addresses problems that inline styles do not. Specifically, it is not trivial to apply constraints using inline styles, and media queries and focus and hover states are not supported at all.

Show thread

Anyway, that's my current analysis. If you know of anything I've missed, do let me know!

Show thread

@vinnl Something I noticed when I started using Tailwind is that I didn't have to think about naming any more. That's subtle, but as you know naming is one of the hardest things in programming :). So it removes that friction and makes building UI faster and more enjoyable (not something I thought I'd say about CSS before using Tailwind). Maybe other libraries out there have the same advantage, but Tailwind was the first (and only) utility-based framework I tried.

@vinnl Also, Tailwind is one of those projects that make me a better programmer. By reading their docs and content, I always learn new things. With previous CSS frameworks I just "used them".

Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!