DEV Community

Discussion on: Tailwind CSS: My experience in 2022

Collapse
 
lnfel profile image
Dale Ryan • Edited

Lows
No prebuilt components

While pre-built components helped with development of web layouts for a very long time. Pre-built components add more work by having to be configured EVERYTIME you make a new project. You can technically reuse some of the configurations you have used in the past but that will not work for every project you will have throughout your career as a web developer. Tailwind did a pretty great job on removing this pain when starting a new project from scratch.

HTML code looked jumbled

As if other ways of writing CSS is not jumbled. Consider BEM:

<img class="photo--highlighted photo__img">
Enter fullscreen mode Exit fullscreen mode

Seems better than Tailwind right? Actually no, and that is not the point of using Tailwind. It is always up to you how you name your classes and Tailwind does not care about that. Tailwind is created to aid in making prototyping of custom layouts faster without the pain of overriding css framework opinionated defaults.

When you are done prototyping, you should always merge tailwind classes into components using @apply. This will reduce the file size of your HTML when you deploy to production and will make maintainability of your CSS easier.

Collapse
 
somtookaforr profile image
Somtochukwu Okafor

True, having to always configure pre-built components is definitely more work but isn't building them all from scratch even greater work? Tailwind just makes it faster building it from scratch.

Thank you for the @apply info, although I'm hearing that it is an anti-pattern to Tailwind itself.

Collapse
 
lnfel profile image
Dale Ryan

Pre-built components has never been a goal of Tailwind. If you need a working layout and component prototype real quick without bothering with css, Tailwind is not the right solution.

The issue with @apply only occurs if you have opted too early on using it.

Somebody already provided citation about this but here is the gist:

Avoiding premature abstraction
If you start using @apply for everything, you are basically just writing CSS again and throwing away all of the workflow and maintainability advantages Tailwind gives you.

@apply is there to help you merge classes when the design is ready for production.

Relevant thread about the so called anti-pattern where Adam gives an insight on how to properly use @apply. The infamous article about Tailwind is just a bunch of early impressions about what tailwind does and not what Tailwind sets out to solve. In my honest opinion CSS modules are far more the worst offender in the whole history of CSS, instead of making a css file as the single source for CSS definitions, somebody decides to spread them in multiple files instead.

Thread Thread
 
somtookaforr profile image
Somtochukwu Okafor

Thank you @lnfel , I'll check out the GitHub discussion thread on apply . From what I can see, component based might be the way to go with when using Tailwind.

instead of making a css file as the single source for CSS definitions, somebody decides to spread them in multiple files instead.

I'm not really familiar with modular CSS but from what I've read up on it, isn't that more or less what Tailwind is doing?