Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

On the surface, the markup is pretty damn awful. But if you reach certain level of proficiency, this will definitely speed up development.

<div class="lg:flex lg:items-center lg:justify-between"> <div class="flex-1 min-w-0"> <h2 class="text-2xl font-bold leading-7 text-gray-900 sm:text-3xl sm:leading-9 sm:truncate"> Back End Developer </h2> <div class="mt-1 flex flex-col sm:mt-0 sm:flex-row sm:flex-wrap"> <div class="mt-2 flex items-center text-sm leading-5 text-gray-500 sm:mr-6">

Personally I would prefer Bootstrap over this approach.



It's as if one person was arguing for hard-line separation of style and content, and another person was arguing that in-line is the way to go, and then Tailwind came along and said, "Why not both?"

So now it's the worst of both worlds: an abstraction layer and dirty code.


I think it's a little more subtle than you're saying.

When you use inline styles for everything, you're making the initial development a little faster by making future maintenance and changes a lot harder. (Like, if you decide headings should be italic instead of bold, that's a one-liner fix if you're using CSS properly, but if you're using inline styles you have to individually fix every heading on every page.) So most people have internalized "don't use inline styles for everything" as a general rule.

But if you don't actually care about that sort of future maintenance (or you're charging hourly for it), then using inline styles for everything looks really attractive to you! But you can't literally use inline styles for everything because even non-experts know that using inline styles for everything is bad for future maintenance. So instead you pull in Tailwind so you can say you're using a CSS framework.


I think people that use utility CSS like this will never maintain anything they create. They'll just throw everything away and start over with another framework.


I think that the idea of using well designed CSS rules and classes basically just turned out to not be very useful in the real world (one discussion of the issues: https://speakerdeck.com/vjeux/react-css-in-js)


Or each of your headings is a React/Vue/Web/Polymer/etc component and that's a single edit. Also, sed.


And then the components get bloated to handle logic differences between views of the component, so you went from bloated CSS to bloated components and the need for everything to be a component in order to share a single look and feel.

Once the components get too bloated, you start forking them, and you are back to each page looking subtly different.


Sure, no magic bullet.


Sure. And in that case, just use inline styles (or CSS-in-JS, or whatever else you prefer).


Sure. I view tailwind as a moderate abstraction over inline styles.


"[...] you have to individually fix every heading on every page."

You should have utilized a template engine in the first place. So you'd only have to change the layout/partial/component that is responsible for rendering the heading. Moreover, you could also have extracted the component with css by creating a .title class and using @apply.


But can you realistically change the design centrally of something built only with utility css classes? If the class of an element doesn’t specify its semantics you cannot properly target it in a redesign without updating the markup.


I've never succeeded in that with semantic css either


it would still be a one line fix if you are building with components


Tailwind isn’t the first to take the utility class approach. Atomic CSS was an early implementation of the idea: http://acss.io


It doesn't have to be first to be bad. They can both be bad.


It's not necessarily bad. There are pros and cons to all css approaches. Atomic classes definitely have their fans. It's more a question of which pros and cons matter to you.


uikit as well (the CSS framework, not the Apple thing)


I find that the verbosity is annoying at first, but it makes it incredibly easy to come back to some old HTML and work out exactly what it's doing, and why. Even with Bootstrap, you need to maintain a mental model of what the classes are doing and how they compose, and each custom class adds more complexity to that mental model. Yes, Tailwind has lots of classes, but each class does one thing, so reasoning about the final composition is incredibly easy.


> Tailwind has lots of classes, but each class does one thing

I think this masks a lot of complexity that you have to manage when taking on this approach. And it's not because the approach is good or bad, more what it is or isn't suited for.

The example on the homepage is very slickly presented, but the end result markup is extremely verbose. If I have a Card component, I would like to update them all at once when needed which is what css classes are generally good for. I find BEM naming conventions much more friendly to come back to than markup full of miniature class names.


I had a similar recoil to this approach and then I tried it, and I think they are actually onto something.

Yes, you may have more than one card in your system, but in all likelihood you aren't repeating the HTML for that card more than once, rather you have it in a template of some kind which is called. So while you may have more than one card on your site, you probably don't have the template for it defined more than once. (at least ideally you don't)

For those cases where you do want to extract that code, Tailwind makes that easy to do.

Tailwind is a weird thing and like I said I really thought it was insane at first. But after rewriting a site in it in a few days I have to say it is better than the standard semantic CSS by a mile.


The recommended way to handle components is by using template partials or JS to manage your card component rather than CSS classes. [1]

Though, you can still use BEM with TailwindCSS through the @apply directive. Adam calls the directive a kind of "trick" to get more devs on board with utility-first but it does help a lot of you're used to reasoning about CSS with BEM.

[1] https://tailwindcss.com/docs/extracting-components


My sense is this is for people who do not know css to the level needed to implement BEM. Also, it replaces the cost of knowing css and naming things (class names) with the cost of learning the tailwindcss classes.

I will stick to BEM + colors and sizes maps because this feels almost like using the style tag on each element.

For non-css expert engineers writing spa components, tailwind can be useful.

I can also see that it’s not trivial to mix tailwindcss and scss processors so it’s a no for me.

It has the benefit to limit spacing and color sets to presets but I already do this in my BEM codebase.


what is BEM?


Block-Element-Modifier, a way to structure your CSS. http://getbem.com/


You can work with components too, just use the @apply directive. https://tailwindcss.com/course/composing-utilities-with-appl...


It’s common, even expected, to extract that card into a component of some kind (React, web components, mustache template, etc) so you still only have to update the css once.


Your components often get bloated since you have to account for subtle business logic differences between views.


Isn't that what the container/component split is for? Presentation logic in a container, markup and styling in a component. If you need to reuse the same visual component in logically different contexts you create a new container that mangles the props as appropriate.


Yeah, you can. I've just seen this result in really complicated components. Other styles of CSS naturally separate presentation from html markup generation, so the cost of forking and specialized components is much lower.


Sure, until, you need a variation on that card for some elements, and add some other tailwind classes to the HTML to do it. Everything seems to work fine for a while.

Then you update the styles of the card again but the new styles clash with the ones in those tailwind classes and you end with broken styles in some elements.

Mixing components and utility classes is a recipe for future chaos.


How is that different from any other css? I'd argue any css solution would have this problem with components.

edit: thinking more, you can override classes. So yeah, maybe utility/atomic classes are not as effective here.


No, you just create a new card component and adjust the tailwind classes on it.

Or, if it is a minor change, then conditionally include / exclude a small subset of tailwind classes.

The point is to not write your own CSS, you only use tailwind classes. In this way you can look at the template for each of your components and reason about / edit their style and layout easily.


This exactly. With more traditional approaches it can be very difficult to find exactly what css rules are affecting what elements. Tailwind is more verbose but also requires a lot less context to understand what’s going on.

It also makes responsive styling a lot easier in my experience.


If each class does one thing, what's the advantage over using inline styles?


It's good across projects/teams/job too. You know what everything does. You don't have to learn every btn--rounded--primary thing for every app you work on.


Another reason Bootstrap > Tailwind is consistency & context. Adding the class `alert alert-danger` to a div tells my coworkers that it's an "alert" & it will look like an alert everywhere. If I want to change how alerts look, I change the CSS

With Tailwind you'd have `bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative`. Then I'd have to change my HTML everywhere to update the appearance of alerts & its not always obvious that I'm looking at an alert in code.


> Then I'd have to change my HTML everywhere

Nope. Once you see same (sub)set of classes repeated, you would instead define .alert and .alert-danger using Tailwind's @apply directive, and you now have a single place to change how your `alert alert-danger` looks :)


Isn't that like recreating bootstrap component again? It's just that this time it's not created by default at first


I'd imagine a reusable React component something like:

<Alert type="danger"> Are you sure? </Alert>

Of course this solution would work in other templating engines as well.

The alternative would be extracting css components:

.alert { @apply px-4 py-3 ... }

.alert-danger { @apply bg-red-100 .. }


OK, this:

<div class="lg:flex lg:items-center lg:justify-between">`

Isn't this why we have CSS preprocessors? So we can do:

<div class="description-of-what-this-is">

.description-of-what-this-is { .lg_flex() .lg_items-center() .lg_justify_between(); }

Assuming there's enough complexity beneath the mixins to justify their use -- some of these might just be CSS properties.


You can do this with Tailwind as well: https://tailwindcss.com/docs/extracting-components

// in JS, then build .btn-blue { @apply bg-blue-500 text-white font-bold py-2 px-4 rounded; }


This feature makes it a very progressive library for various stages of development. Inline earlier, then gradually extracting the style for reuse in later stage. Besides, their documentation is really good for one to learn those newer css concept.


In that secenario why even use tailwind? Why not just normal css?


That assumes you have the means, the knowledge, and the time, to go through a build step.

What you find to be clean code might go the opposite way for someone (i.e. why would I use scss if utils are all I need?).

You might work with large scale apps where BEM may make more sense. You might work on a site builder where utils might be better. You might be creating splash pages for marketing purposes where going for element selectors may be enough.


Just use view templates to capture this if you need to reuse.


That's fair. However, it is pretty straightforward to extract these to something reusable using Sass, css-modules, or templating (Handlebars, Nunjucks, React, etc).

So you can move really fast and experiment when you need to, and then extract to something shared when you're ready to DRY it up.


Nobody likes the look of utility css frameworks, but once you use it, it’s tough to go back.


At that point, you're basically just using inline styles. Don't get the real benefit of this library.


You can move those clases into a css file.

button { @apply border bg-white; // ... }


i've grumbled about this, too.

Tailwind recommends PurgeCSS, but i'll plug my own lib here:

https://github.com/leeoniya/dropcss

i have a specific section on how to handle tailwind's unorthodox classnames:

https://github.com/leeoniya/dropcss#special--escaped-sequenc...


that is some awful looking css you have there.


The classes are exactly why it shines




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: