Hacker News new | ask | show | jobs
by zamalek 28 days ago
What I don't get about tailwind is: why not just use the style attribute at the point?
2 comments

With Tailwind:

    <button class="bg-blue-600 text-white px-4 py-2 rounded">
With style:

    <button style="background-color: var(--color-blue-600); color: white; padding: 8px 16px; border-radius: 4px; border: none;">
Now more interestingly, Tailwind with hover and focus styles:

    <button class="bg-blue-600 hover:bg-blue-500 active:bg-blue-700
      text-white px-4 py-2 rounded transition-colors
      focus:outline-none focus:ring-2 focus:ring-blue-400">
That’s not possible with the style attribute.

Even more interesting with Tailwind, a div with dark mode and responsive styles:

    <div class="
      bg-white dark:bg-zinc-900
      p-4 md:p-8
      rounded-xl
      shadow-sm dark:shadow-none
      border border-zinc-200 dark:border-zinc-700
    ">
That’s not possible either with the style attribute.

Now your first instinct might be to "that’s unreadable", but keep in mind HOW you actually read and write this code. You’re not actually reading it to understand what it does like you do with iterative code. You see how the browser renders it, and you just adapt the code. Tailwind code is mostly write-only and maintained by viewing what the component looks like. This code doesn’t need to be reusable either, the whole component needs to be. The Tailwind code inside is unique.

> Now your first instinct might be to "that’s unreadable", but keep in mind HOW you actually read and write this code. You’re not actually reading it to understand what it does like you do with iterative code. You see how the browser renders it, and you just adapt the code. Tailwind code is mostly write-only and maintained by viewing what the component looks like. This code doesn’t need to be reusable either, the whole component needs to be. The Tailwind code inside is unique.

I think this helped me finally understand the chasm between tailwind proponents and me. I just don't think I'll ever be part of the "keep painting each room a slightly different shade until it looks right" camp, when there's the "you can buy all the same color paint ahead of time, and even have some left over for the next five rooms you build" option right there.

Yeah, tailwind as write-only code definitely tracks. I guess some people like that. Not my bag though.

> keep painting each room a slightly different shade until it looks right

You’re still not getting it. That’s NOT what Tailwind is, because Tailwind works in a design system way, so when you use text-sm or bg-sky-400, you’re using variables that can be configured to suit your needs and keep a consistent design everywhere. Tailwind defaults and configurability played a huge part in its success.

> Tailwind code is mostly write-only and maintained by viewing what the component looks like.

I’d add that almost all code is like that, if you mean you only write it once and only look at it again if you need to make a change. And with Tailwind you generally only need to look at the one component, instead of having to go to a separate CSS file to look, and then look through the codebase to see if that code is used anywhere else.

It's much more verbose and can't do everything Tailwind can anyway.

E.g. how do you style a child on parent hover with the style attribute?