r/reactjs • • Aug 13 '23

What do you think about Tailwindcss?

I consider using tailwind css. I was wondering if anyone could elaborate about potential disadvantages and cons of the framework. Thank you!

3 Upvotes

69 comments sorted by

42

u/ZerafineNigou Aug 13 '23

I personally really like it, I think it makes writing css faster and easier, the tooling to order classes is really useful and I really like the way it makes systemizing colors, fonts and others really simple. The fact that it provides a lean CSS solution is nice too.

But to play devil's advocate:

It locks you into reusable styled components over reusable styles (which I think is a good thing but some people do not like it).

I think the biggest argument against tailwind is that it forces you to combine your HTML and CSS, again I personally like this, but to some people they prefer it separate.

Another technical issue is that inline classnames can get long and hard to read though personally I use clsx to break it up into several lines which fixes that though it does come with a minor computational cost that some people might not like.

Another big point against tailwind is that it does not do that great with dynamical stuff since all classnames have to be known during compilation. There are various ways to go around this but it's definitely more complicated than in CSS where you just dynamically set it and it's good to go.

And finally some people feel that tailwind is too far from CSS which means that 1) transitioning into a pure CSS solution will be harder later, 2) transitioning from a CSS solution (for new hires) is harder and 3) it's more likely to become irrelevant as new and new libraries come out compared to CSS which is basically a browser level feature.

2

u/EvilDavid75 Aug 13 '23

Overriding a component style is also difficult imo. The most elegant approach is using the @apply directive but that essentially involves creating css files which defeats one of the main advantage of of tailwind.

6

u/NeitherManner Aug 13 '23

I think one quality of tailwind is that it helps to guide to good css practices. If there isn't for example 65vw utility class, it probably means you should try different way to accomplish that.

6

u/kredditbrown Aug 13 '23

TailwindCSS also seems to be a big contributor for popularizing token/utility based styling which I appreciate. Components on a screen need to work together to build a nice UI, something I felt CSS modules put as an afterthought and treating styles in isolation which you never really have on a website in the first place

-1

u/[deleted] Aug 13 '23

I use pretty close to that width in ALLLLLL my projects.

I use a lot golden ratio in my projects, so your saying that i shouldn't, cause tailwind doesn't include 62.8/63vw?

4

u/NeitherManner Aug 13 '23

I think max-width works better. If you use 62vw it can get quite wide on ultra wide monitors for instance. And small laptop might not be wide enough with 63vw.

-1

u/[deleted] Aug 13 '23

totally correct.

But then the 62w becomes the center, and 38vw becomes the unused margins (19 62 19), and then i split up the 62 display area again with the golden ratio,

You might notice twitter sort of like that also, lotta of side space

4

u/quakedamper Aug 13 '23

Can use custom value easily with square brackets like w-[63vw]

5

u/[deleted] Aug 13 '23

Again i'll pass on tailwind, just like i passed on bootstrap 8 years ago. Writing pure CSS is easier and more powerful.

9

u/quakedamper Aug 13 '23

I used to knock it too before I tried it but it’s a whole different thing to bootstrap and more powerful when you know css

2

u/[deleted] Aug 13 '23

I've used it,

I've even used the pre tailwind versions, as tailwind wasn't the first to do this, they just marketed it well, i mean he made $250k plus first weekend he released the paid version.

I try and be metal in everything i use, why i now code backends in rust, and not js/ts. More magic you add to anything, will eventually leave you hitting edge cases it wasn't designed for, like when i want incrementally add micro animations etc.

2

u/shivangg Jan 17 '25

Why Rust if Assembly is closer to the metal. Why not just solder the logic in metal itself. That's the closest to metal 🤡

3

u/dben89x Aug 13 '23

I've recently found myself being practically forced into atomic css and I'm struggling with one main issue over all others. I'm very curious how others approach it.

With standard class names, it's very easy to just inspect an element in the browser, modify its styles, and get a general intuition for how it's connected to all its siblings, parents, children, etc. This is especially helpful for debugging when a style is off. You just inspect the element, modify it, and change it in the code. With BEM, you can easily just look at the component name (like UserCard__title, and find it in the code easily. With atomic css, it just shows a div with dozens of auto generated class names that make no sense and give you no context for what element you're inspecting, and where to find it in the code. Looking at html generated by something like tailwind makes my head spin and I haven't been in the inspector since.

How do you get around this? Do you have a different way of debugging your styles? Do you not spend much time modifying things in the inspector? Do you use different tools that make the connection for you?

4

u/PsychologicalCut6061 Aug 13 '23

I have the same preference as you.

This to me feels like a difference in DX (developer experience) for more traditional frontend devs used to CSS versus the preferred DX of, well, full-stack devs.

The trend over the years seems to be management putting too much frontend burden on devs who don't get much CSS training and then those devs trying to take as much thinking about CSS off their plate as possible.

I've personally been heading in the direction of just making really better component systems, and if a team wants it in Tailwind, that's probably not a hill I'm gonna die on. My only hill to die on is that things don't become a mess.

Edit: However, I still prefer being able to work directly with CSS or Sass. I've spent a few years with CSS-in-JS and see its benefits, but it's still annoying to me.

2

u/ZerafineNigou Aug 13 '23 edited Aug 13 '23

I feel like tailwind is different in this case since all classNames are intuitive of what they represent. You cannot mass-edit as easily the style of several elements in browser that is I suppose a fair loss but with HMR you can just edit the code and not have too much issues.

I usually if I am really unsure what's going on just edit a single element then once I know what I am going for I just edit the code and let HMR take it away.

Storybook to prepare elements ahead of time also really helps. Since you already have a mindset where you are making styled components first instead of reusable styles once you are outside of storybook you only really do fairly minor styling, mostly layouts. So most of your issues will be apparent with storybook where what is which style is very apparent.

4

u/__data_cactus__ Aug 13 '23

it removed a lot of mental ovethead for me.

it took a bit to get used to, but once you embrace tailwind's mental model it's hard to go back.

obviously, there are tradeoffs. for large projects it bloats the html and it becomes slightly more difficult to customize as opposed to other methods, but for small and medium projects it provides the most versatility and speed imo.

2

u/yairharas Aug 13 '23

it removed a lot of mental ovethead for me.

it took a bit to get used to, but once you embrace tailwind's mental model it's hard to go back.

obviously, there are tradeoffs. for large projects it bloats the html and it becomes slightly more difficult to customize as opposed to other methods, but for small and medium projects it provides the most versatility and speed imo.

Can you share a specific example where customizing was particularly challenging in Tailwind, compared to other methods?

5

u/madovermoto Aug 13 '23

use it at work, pays my bill that's all, convenient for building something template-ey designs quickly.

Personally, I like the total control of bare CSS (SCSS modules), being able to customize gradients, shadows, complex layout without messing with config is important for me when designing from scratch.

when I am designing from scratch, I want to experiment with all things , but tailwind comes in my way. I do prefer tailwind however if design is boring

4

u/_Pho_ Aug 13 '23 edited Aug 13 '23

I went full circle on it, I hated it conceptually because it required memorizing a bunch of shorthands, but after being forced to learn it for work, I think for prototyping and the 80% of projects which don’t require super thorough css, aka most businesses, it’s convenient.

But I still posit that it’s worse than React JSX inline styles, with those I don’t have to remember key names and multiples and I get better linting, and I don’t have to add additional tooling. The main “a ha” of tailwind is not having to define a separate abstraction for styles, which React already has.

If it’s on a project, mazel tov, if not, that’s fine too.

4

u/draculadarcula Aug 13 '23

Some people think utility based css is spaghetti and your css should follow a “cleaner” OOP like approach (BEM, etc.)

One major disadvantage is if you are building a component library that needs to be cross framework (like a design system), tailwind is bad for this. The styling can’t really be shared between projects that differ in framework because you’re not writing any css

11

u/azangru Aug 13 '23

I would rather write my own CSS than go through the translation layer that is Tailwind.

9

u/dfltr Aug 13 '23

Tailwind is ideal if you want to start with the idea of reusable utility classnames and end with an unreadable, unmaintainable pile of over-decorated markup that can only be fixed by lighting the whole thing on fire and starting over.

2

u/PsychologicalCut6061 Aug 13 '23

I have a strong belief/fear that this is probably what happens on most teams, even with the best of intentions.

I've worked with people who insisted that anything but CSS-in-JS was a circa 2005 massive stylesheet nightmare (not true, and I had professional experience to back that up) and that I just didn't know the power that it held. And then saw that they'd implemented it in the most ridiculously sloppy way possible. I've actually come to work with that tech for a few years and don't hate it when it's the right tool, but my faith is so low.

4

u/stjimmy96 Aug 13 '23

If used properly I think it's great, if used badly it makes the HTML really cumbersome.

The key point to me is: HTML should contain the layout definition of the page (or component, whatever), or in other words all the rules that define the position of the element inside its container. On the other hand, the styling of an element should belong to the styling framework of your choice (plain old CSS, styled components, whatever).

Tailwind allows you to do both with its set of classes. All the layout utilities (flex, grid, margin, padding, etc...) are awesome. They make the HTML rich and self-explanatory for everyone reading it. I'm not a fan, however, of putting all the styling rules there as well which is something tailwind allows you to do as it makes the HTML really cumbersome and hard to read.

So yeah, I like it but I think it needs to used with caution.

4

u/AdministrativeBlock0 Aug 13 '23

The only serious 'con' is that it doesn't work with dynamic style names. Eg you can use 'bg-red-400' but not bg-${color}-400. There are workarounds but they bloat your CSS a bit. Certainly no reason to avoid it. You just have to be aware.

-2

u/dabe3ee Aug 13 '23

Why you want this kind of unreadable code? Just conditionally apply different class, but never do this. If you really need this kind of behaviour, create variable before return const color = ‘bg-${isRed ? red : blue}-400’ and add it to element. But again, this feels strange

10

u/AdministrativeBlock0 Aug 13 '23

So I can pass a color name into a component and have it render in that color. It's a super common pattern in design systems.

4

u/dabe3ee Aug 13 '23

Just another way to write css. Sometimes its nice to do inline styling and sometimes it sucks if you need to use 50 classes and you cant create dynamic classes - you have you use “style” property which is considered bad practise.

2

u/aawebdevUK Aug 13 '23

It's great as long as used appropriately! I pretty much always use tailwind and it really comes into it's own with react. You need to be thinking in components to really get the full benefit, if you find yourself repeating tailwind in your components then consider whether you need to refactor into another component. If you do this you'll get a lot out of using tailwind!

2

u/theQuandary Aug 14 '23

In the old days, we had html attributes like align, bgcolor, border, height, text, etc. We created CSS to unify and abstract our styling.

Tailwinds circles right back around to what we have already proven doesn't work or scale well.

5

u/[deleted] Aug 13 '23

Its training wheels for css, can't stand it.

0

u/Ratatoski Aug 13 '23

It's damn great! Really quick to use and there being predefined slots is a sort of guard rails. In a lot of project you'll see margin 12px, 1rem, 13px, 14px, 1.2ex etc. Which makes the design feel inconsistent. But with Tailwind you can't fall into that trap.

I used it for work for a few years through TW 2 and 3. With TW2 I sometimes had to add a little CSS of my own. With TW3 that doesn't ever really happen.

I started web dev in the end of the 90s and Tailwind is by far my favourite solution for CSS so far.

Lightweight as heck! A whole website for an organization will be like 4-6kB.

No !important, precedence or wondering "is this in use somewhere?"

The bad? I wish it enforced a certain order of classes because it can get pretty verbose. Having them sorted would help. And for the first few months it felt icky like the inline styling of the golden days.

7

u/ZerafineNigou Aug 13 '23

Having them sorted would help

Isn't this what their prettier plugin does?

https://tailwindcss.com/blog/automatic-class-sorting-with-prettier

1

u/yairharas Aug 13 '23

Damn, I like it!

6

u/KapiteinNekbaard Aug 13 '23

What's the difference between...

.customClass { padding: 1rem; }
className="p-4"

(Let alone the use of arbitrary values like class="p-[1rem]")

...in terms of consistency? What prevents someone from applying p-5 instead of p-4? You still need some conventions or a styleguide to determine the specific values that you want to use across elements.

Using global CSS variables like --padding-md: 1rem that can be applied everywhere would make a lot more sense to me. It abstracts away the value, no need to think about it anymore.

1

u/yairharas Aug 13 '23

Thank you for you detailed answer!
What could you say about the maintenance challenges as the project scales up?

2

u/zaibuf Aug 13 '23

The bad? I wish it enforced a certain order of classes because it can get pretty verbose. Having them sorted would help.

https://tailwindcss.com/blog/automatic-class-sorting-with-prettier

2

u/KapiteinNekbaard Aug 13 '23

I wouldn't use it, maybe for a quick prototype, but not for a large project.

  • Developers (especially new ones) will learn Tailwind instead of fundamentals of CSS. You'll be googling "how to do X in Tailwind" all the time.

  • If you understand the box model, then working with CSS does not need to be hard at all. I never really had an issue with CSS class/style collisions. If you use UI components (basically every JS framework today) to build your UI, you write modular CSS that is scoped to the component. You should not be needing complex style overrides with high specificity like .one > .two > three > ...etc, if that is the case, create a new component.

  • Extra dependencies/tooling means more complexity and extra maintenance. Extra build step in the build process.

  • CSS you write today will always be backwards compatible. What if Tailwind goes away for the Next Big Thing?

  • Can all new CSS features be adopted by Tailwind? I don't know

  • Long inline classnames. Essentially you're just doing inline CSS, but with classnames. People come up with IDE plugins to "fix" that, but that is just a band-aid solution for something that didn't need fixing in the first place.

-1

u/michaelfrieze Aug 13 '23

Tailwind is just CSS. It’s not much different than making your own utility classes.

2

u/KapiteinNekbaard Aug 13 '23

Have you read the installation guide? It comes with it's own configuration file, you need to run a build tool that scans your file so it can trim down classnames to the ones you are using.

You're ignoring my point about the build step. It's not the same as importing a single CSS file with utilities.

1

u/michaelfrieze Aug 13 '23

I didn’t say that tailwind is exactly the same as creating utility classes in a single CSS file or imply there wasn’t a build step. Obviously, there is a build step but that’s not a bad thing.

The classes you see represent CSS. You can hover over the class names and see the CSS that gets applied. Tailwind gives you utility classes based on best practices, that’s the main idea. The build step provides a lot of benefits that you wouldn’t get just by importing the classes in a single CSS file.

0

u/Brave-Job7363 Aug 14 '23

the JIT build mode is the one makes tailwind popular lol, in the early days of tailwind you have to import all the class (super laggy when using devtool) or have to manually allow each subset of class to be imported. At the end tailwind will only generate all the classes that you use across all pages into a file and then import it, not such things like build the CSS file each time you get the page.

2

u/michaelfrieze Aug 13 '23

You can hover over any of the class names in VSCode and see the CSS.

2

u/[deleted] Aug 13 '23

This topic has been talked about multiple times, you should find plenty with a simple search on reddit…

1

u/slgotting Jun 13 '24

Another issue, not sure if its been mentioned, but its hard to maintain a standardized theme throughout the app.

This is the primary part I view as an anti-pattern

When you make changes to a button and wanted it applied to every button in the app, you have to make sure you find every button that has those styles.

I still use it because it solves a lot of other problems for me, and the @ apply directive should be used. People argue that then you're just using css, but tailwind adds the handling for screen sizes and dark mode and various web browser's syntax, etc...

1

u/SaltyBaoBaos Aug 13 '23

I thought about using tailwind after doing some research and testing, but I ended up using Panda CSS.

1

u/Maleficent_Slide3332 Aug 13 '23

i thought it was weird when i first started using but i have learned to love it

1

u/[deleted] Aug 13 '23 edited Aug 13 '23

It's a game changer: not only does it help one write CSS faster and simpler, but it also reduces their bundle size by only generating the CSS that's used in their project.

There's also an eslint plugin for it.

1

u/nazzanuk Aug 13 '23

I personally think it adds an extra non-standard learning/abstraction layer and creates unnecessarily verbose html/jsx.

But plenty of devs swear by it, you just have to try it and see if it works for you.

1

u/treasurewalker Aug 13 '23

Google css utility class framework disadvantages

1

u/octocode Aug 13 '23

good enough for small projects, but if you try to build anything even remotely complex, you will hate it

also if you’re a beginner just learn CSS first. having to learn both CSS and tailwind’s arbitrary abstractions is a nightmare

1

u/ConsciousAntelope Aug 13 '23

I'm a guy who's into ready made UI components. I do like it though but a lot of my time is wasted on writing those classes manually. And again those who write good code will write good code. Ive seen juniors obscurating with arbitrary values, overwriting the previous classes by adding new one instead of removing old one. If you follow the best practises and constraints it provides, it is a solid choice

1

u/roofgram Aug 13 '23

Inline styles with extra steps.

1

u/klysm Aug 13 '23

Shitty API for CSS, not that the alternatives are much better. It’s difficult to maintain consistency in large projects

1

u/reddit_is_meh Aug 13 '23

I prefer raw css/sass/etc.

Love having proper control of what's going on.

Even on big projects with lots of devs there's plenty of ways to keep everything organized using a mix of naming convention, scopes styles depending on your front end frame work, etc.

1

u/Mestyo Aug 13 '23 edited Aug 13 '23

The positive things I can say about Tailwind are these:

A community-standard name convention for CSS variables has some inherent value. Hypothetical 3rd party component libraries using it come with less overhead, too.

Everything else about it, in my opinion, is just bad. The lengths front end developers go to not have to tab to a different document is outright comical; sacrificing dozens of existing ecosystem benefits, while creating a need for additional tools to solve the workflow problems introduced by the tool itself.

That being said, at least it's a better fad than what CSS-in-JS was, as it doesn't impct runnable environments and incurs no runtime cost.

1

u/InternationalFly3917 Aug 13 '23

Tailwind is trash us vanilla css let's dependency less headache believe me

1

u/greentiger45 Aug 13 '23

I’m a big proponent of styled components but have recently dove into tailwind. While styled components is easier to use imo, tailwind is simpler to apply basic css. The only issue I have with tailwind is how verbose things can get when applying styles.

1

u/ktravelet Aug 14 '23

I wish I knew enough raw css to not need a framework but until that day comes, tailwind it is.

1

u/edmblue Aug 13 '23

I love it with my heart

1

u/Zinter71 Aug 13 '23

Is like writing CSS but easier. I actually learned CSS with Tailwind. I guess you already know some of the PROS towards using it in your project, so here are the cons I've encountered:

  • Sometimes there are new features that CSS has already implemented, and tailwind takes some time to catch up with it.

  • If you are not using components or a component framework, it might be more trouble to use tailwind. So just use CSS (personally i still use tailwind bc im faster with it lol)

  • It is kind of verbose, so you might encounter repetition on class names and stuff, but that is why Tailwind really shines in production and modern frontend frameworks. You can reuse your components.

Besides all this, i think i'm coming to the conclusion that tailwind is kind of universal by now in the frontend world. for example, the shadcn library is awesome and you can build anything with it because it uses tailwind. I'm glad we are passed that js object like notation for applying styles. but is all about preference.

0

u/kitsunekyo Aug 13 '23

pure love. (pure disgust, before i got forced to use it in a project) #classic

0

u/cyberduck221b Aug 13 '23

I like the autocomplete 👍. Also it's very handy. Very easy to make reusable styled components!

-2

u/kaizoku_95 Aug 13 '23

It's great !. Was very skeptical to get started with it, but now that I have extensively used it, I don't prefer any other methods. I would rather have long classNames than having separate files for each component.

-2

u/octod Aug 13 '23

It works, it’s easy to learn, it’s easy to install/upgrade, it’s good if your team is not very skilled with css and it’s not a burden like component libraries or bootstrap shit.

-2

u/IamZeebo Aug 13 '23

Its amazing and I suggest you just try it for yourself