It's 2022, and it's officially been 5 years since Tailwinds launch. Now some might ask what exactly is Tailwind CSS, well according to their websit...
For further actions, you may consider blocking this person and/or reporting abuse
If you feeling like the Tailwind's classes are bloated, you can have some options:
Write normal classes and use
@apply
tag to write tailwind's classes inside them. For example:Do both things above.
Using semantic classes and putting everything in CSS with
@apply
is the only way I can see Tailwind being used. Anything else is just two steps backwards.Then you have not understood why tailwind was made. No offence it is your right to think like that and I have thought the same. But using tailwind now daily is just the creme on the cake. It’s easy and awesome :)
No, I get why Tailwind was made, and how it's generally used. It's just that I think those uses are detrimental to the web.
A few days ago I found this interesting post about tailwindcss.
javascript.plainenglish.io/tailwin...
I must say that the only way I found tailwind usable is via creating group classes via @apply
I came to tailwinds a couple of years ago searching for a lighter solution because I was tired of bootstrap and its heavy css file.
I tried bulma, foundation ui toolkit and MUI too but none of them convinced me
@faridsa so what do you think about tailwind now, do you think it's positive? should we use
This is a good article and fits my point of view quite nicely.
My personal position is using tailwindcss to solve fast mockups or little projects as landing pages, because it is really light in final css file.
But when it comes to large and long term projects I do prefer to create my own stylesheet using css variables and necessary classes with sass. I found that more sustainable.
In any case, I think that each developer ends up using the tool that best suits their modality.
Nice. I’ve never checked out Tailwind because the cluttered HTML is just not my style but this apply feature makes it look a lot more appealing. Glad I stumbled across this comment!
Wow, I didn't know of this. Thank you @mangor1no
I agree - dividing code into small pieces like components helps a lot and for me tailwind is great example of framework / library that force you to use some patterns in code.
Using
@apply
isn't great idea. Tailwind after build removes unused classes so if you create new one it won't be removed but created as new one which means that Tailwind doesn't make sense to use - it now reminds me some things like BEMI don't see why would you add an
apply
instead of writing pure css 💅 Its fun 🎉last time i checked using tailwind @apply it converts the classes to css and begins to bloat everything as you're not using utility classes anymore. is this still true?
I'm very strongly against using Tailwind exactly for the list of "highs" you wrote down... Granted I'm looking at this mostly from a React perspective... But every UI framework out there offers those same highs, but with less of the lows. My major low for Tailwind is that you have to handle all accessibility coding yourself, like adding element
role
andfor
attributes. I always prefer using a framework with pre-built components that give me options to override styles by adjusting a theme and using CSS in JS solutions.I’m also not a fan of tailwind.
One of the highs is better understanding css. Because trying equalivent class with inspect element. I think you can also do that with changing the css value in inspect element.
Funny enough I use React too but yes I'd prefer a CSS framework with more configurable prebuilt components like Bootstrap. Maybe with time Tailwind would have this but for now I'm still confined to having to build from scratch up.
If you write one time a reusable component, you can reused it also on other project. For maintainability you can create own package.
Thanks @rkallan , creating my own package might actually be the way to go in the long run.
Every framework has its purpose.
Tailwind has made it easier for me to produce web pages faster without having to style everything with vanilla CSS.
Bootstrap is great as well. ReactStrap is what I use more.
Again. Each to their own. That’s the best part about programming.
So many different solutions 😎
Great article by the way
You can found tons of tailwind solutions too, even for complex layout tailwindui or even CSS component library like daisyui
Thank you @pengeszikra , will be sure to check them out.
github.com/michal-wrzosek/cntl
This utility 👆 was a huge help for me when dealing with the "short comings" of tailwind. Grouping the utility classes in list notation is way cleaner IMO.
As many have mentioned, separating tailwind from the markup is an anti-pattern. The value prop is to stay within the markup to style and not have to search/context-switch. it definitely takes getting used to. the key for me was IDE integration. once you setup your IDE properly, it can suggest/auto-complete all the tailwind utility classes. and not just base tailwind either. if you customize things like your color palette, those classes will be suggested as well.
if you do end up using
cntl
or a similar lib, there may be some additional tweaks to make to the IDE integration. but once that is working, i found tailwind to be a great dev-ex!Thanks a lot @afreidz . I'll be sure to check out the utility package.
If you're using React, you can hide away the jumbled CSS in a UI Component, that way all styling is encapsulated within the component, and you don't have dangling classNames all over the codebase.
Example here: gist.github.com/lifeiscontent/84bb...
Thank you @lifeiscontent , so basically CSS in JS components ..like Styled Components? I'll check out the example.
I really like your article about a new experience you had lately. It shows that you are open minded and can adopt new things when needed. If you choose to go your (private) future with Tailwind or not, just keep up the great work 💯
Thanks @yuridevat
If you use javascript frameworks, you can create javascript component to prevent repeating your styles.
Thanks, I will try that out next time .
Tailwind in html is ugly. The only way I use it is with the
@apply
. You’re right about the sm, lg prefix for responsiveness. It makes life easier.The responsiveness does make my life a lot easy than stating a hundred media queries in separate stylesheets!
If you have to use 100 (or whatever) media queries, maybe your CSS is inefficient? Or even more likely, the design isn't good (won't break cleanly between devices so you need different breakpoints on every element)? I say this as someone who was doing this constantly in my first dev job until I realized (after 2+ years) that having a media query every 50 px is a sure sign that your CSS and the design both suck :D Having said that, sometimes you gotta do what you gotta do.
Well i was going for hyperbole in that comment...
But you aren't too far off base! I am sure I've written a lot of bad css haha.
We all have! 😅
Are there other good libraries that offer pre-built components for tailwind?
tailwindui, flowbite, daisyui etc
I tried out Flowbite React but its components were not easily configurable and were more a headache than a solution.
Put commonly used tailwind ui libs here only, had experience with daisy ui and Vue before
I must say I do not have experience with any of those. I did take a look at Tailwind UI a little while ago and it looked good, but then I found out you have to pay for it :S
Well yes, but it doesn’t mean it is bad or smth. Their templates are pretty well developed
That's why you need to create a component or use PostCSS with TailwindCSS to create utility classes 😁
A quite balanced review from someone new to Tailwind.
Hoping to see the v2 of the article when you're more experienced with it
👍
Thanks @orimdominic , it'll be sure to come.
Good read and very informative. I always look forward to your articles
Thank you
this is helpful, thank you for sharing
Yes, it's.
From Tailwind documentation on Avoiding premature abstraction:
And if you allow me to put my personal opinion on top of that, everyone that feels
@apply
is unavoidable with Tailwind are just either:I do component-based development in vue and split stuff by functionality and reusability. I use \@apply in each component's tag.</p>
Well detailed, will always check in for more
Thank you
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.
As if other ways of writing CSS is not jumbled. Consider BEM:
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.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.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:
@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 opinionCSS 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.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.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?
Nope, it isn't an antipattern. If a component has a ton of classes then it's a you problem, not a tailwind problem.
Tell me how this statement is incorrect. Developers learn more about custom, federated styleguides and css using Tailwind vs using bootstrap. I get it, a strong css dev will see Tailwind generally as an unnecessary additional step when they could have just written the classes themselves, however when working in large teams on many projects it rarely matters how great one developers code is if nobody else can easily adopt it.
I wrote a bunch of CSS since 2007 and confident to write them fast and well. Tailwind just takes the writing part so I can prototype a layout or component with less time consumed if I were to write my own css for every project I have. You should have said:
Now please define unnecessary.
I understand you @somtochukwunigeria many of us have been (or still are) in your situation, where your personal preference is overridden by the force that puts food on the table.
At the end of the day, it all boils down to which team you are working with. I have noticed that the argument for tailwind or bootstrap is mostly (I repeat mostly, not all) by people who are either solo developers, freelancers or working in a very small highly flexible team that are not too strict on code base optimisation and structure.
No matter how much one loves tailwind, if the company you work for opt for bootstrap, you will use bootstrap. If the team opt for tailwind, no matter how much you love bootstrap, you will use tailwind.
I am yet to see someone leave a company because the company switched to a css framework that was not to their taste. (Note: there may be people who have made this move, but I have not seen anyone do so in my 6 years web developer journey).
I have rather seen senior developers adopt and adapted to technologies based on product/clientele demand at that point in time.
Just because a team get profitable experience with tailwind, does not rule out the benefits other teams have from bootstrap and vice versa.
And for the records, I use tailwind (most times), it’s a utility system that allows developers to focus on System logic rather than User Interface. However I prefer writing css using “Sass” and/or “bootstrap sass” - I am more efficient and faster. 😎
I agree, at the end of the day it all boils down to what technology the organization uses. It's your job as a good developer to be able to adapt to the ever present changes but we are still allowed to have preferences in these technologies we often jump unto. I've always used CSS/SCSS and Bootstrap for as long I can remember so it's grown on me so trying Tailwind was a different feel for me but I'm getting the hang of it. @elnobun
Because of your strong background in vanilla CSS/SCSS way of styling the markup, tailwind will not be much of a hassle other than the technicalities of "class names" used to represent a css property. This will keep you going back and forth the documentation until you get a hang of it.
I can tell: If your company is building a Product, and want to focus majorly on the product functionalities rather than styling user interface, then tailwind may be a viable option indeed, as this will save cost, meet product milestones quicker and offer deliverables within reasonable time frame while the team focus mainly on backend.
I wish you the best. Please update us on your overall experience when you are completely hands on with tailwind. Cheers! 👍🏽
Lol yes I still do, the Tailwind documentation is always frequented for better understanding.
Thank you @elnobun , I will do that, for now I'll just need to keep familiarizing myself with it.
can you please some good article on the atomic design thing?
It's not, taliwind already includes helpful utility classes. SASS and BEM are not utility frameworks.
Tailwind is made for components. If you're repeating stuff a lot then you aren't using components enough most likely.
I think you should read the tailwind document
I have @06ergin06 .
tailwind is one of the great projects.