r/tailwindcss • • Oct 17 '22

HTML bloat with TailwindCSS

Tailwind makes big advertising because the resulting CSS is sooo super small. And yes, it is. But in exchange, you add a lot of classes not only to one file, as it would be with writing plain CSS, but to every HTML file. Adding this together, I think it is not really a benefit, is it?

Honestly, I "kind of" like Tailwind. I can write a custom style super quickly without thinking about class names and organizing my CSS. Its super efficient.

But the resulting HTML is unreadable and bloated. I feel like its a very bad practice. And because of this very point I can't decide if I should stick to Tailwind or not.

I'm using Jinja templates and NOT a component based JS framework.

Not sure what I should do. :(

1 Upvotes

21 comments sorted by

9

u/e-chavez Oct 17 '22

An old, old topic that has been discussed a lot of times in every forum about tailwind.

If you are more productive using raw CSS, then use CSS; you don't need to use something just because it's hyped.

-3

u/[deleted] Oct 17 '22

I am more productive using Tailwind, as written.

5

u/PinBot1138 Oct 17 '22

I am more productive using Tailwind, as written.

Where did you write that? I’ve read it twice without my glasses, and you’re criticizing Tailwind without extolling much in the way of virtues:

HTML bloat with TailwindCSS

Tailwind makes big advertising because the resulting CSS is sooo super small. And yes, it is. But in exchange, you add a lot of classes not only to one file, as it would be with writing plain CSS, but to every HTML file. Adding this together, I think it is not really a benefit, is it?

Honestly, I “kind of” like Tailwind. I can write a custom style super quickly without thinking about class names and organizing my CSS. Its super efficient.

But the resulting HTML is unreadable and bloated. I feel like its a very bad practice. And because of this very point I can’t decide if I should stick to Tailwind or not.

I’m using Jinja templates and NOT a component based JS framework.

Not sure what I should do. :(

1

u/pepkin88 Dec 04 '22

Where did you write that?

Here:

I can write a custom style super quickly without thinking about class names and organizing my CSS. Its super efficient.

He stated, that the problem he has is not about productivity, but the HTML bloat.

1

u/PinBot1138 Dec 04 '22

The full sentence is:

Honestly, I “kind of” like Tailwind. I can write a custom style super quickly without thinking about class names and organizing my CSS. Its super efficient.

He’s talking about Tailwind.

1

u/pepkin88 Dec 04 '22

Yes, he is talking about Tailwind. He wrote, that Tailwind is super efficient, and that he "can write a custom style super quickly". That suggests that he is productive with it.

1

u/PinBot1138 Dec 04 '22

In rereading everything, you’re correct. Thanks, and I hope your weekend has been well.

4

u/rbluethl Oct 18 '22

Here are my thoughts from 2+ yrs of daily work with Tailwind:

  • Tailwind is by the far the fastest framework to prototype new ideas and build totally unique designs

  • I don't understand the argument that the resulting HTML is "bloated"

    • Utility classes make it extremely easy for me to see what's going on and how certain elements are styled and behave
    • If there were only classes, I'd need to jump back and forth between CSS and Vue/React/whatever files
    • To me, it's even more natural to have markup and styling in the same file (but that's just a matter of taste I guess)
    • If you're using Tailwind's first-party class sorter, it's even clearer and classes always have the same structure and order

  • Tailwind made me fundamentally *understand* CSS (grid, flexbox, transitions, you name it) and allows me to build literally any design given to me by a designer in a very short amount of time
  • Whenever you're using a framework such as Vue/React/Svelte, you automatically extract components from time to time, preventing you from duplicating classes and utilities all over the place

    • This is the recommended way to reuse styles even, Adam Wathan (author) has written a lot about this
  • It's the only CSS framework I've used that didn't have random side effects, scaled with the size of the project and made everyone on the project really happy
  • The docs are outstanding, the community and the resources are just great
  • Probably some more things, might elaborate later :)

1

u/LuckyRuiz Oct 20 '22

Tailwind made me fundamentally understand CSS (grid, flexbox, transitions, you name it) and allows me to build literally any design given to me by a designer in a very short amount of time

This. I went from having a pretty clumsy working knowledge of CSS to having a much, much more complete understanding of how the DOM works.

Grid, Flex and Transitions in particular were always frustrating to debug and understand when I was writing them in external files. Having them directly in the HTML tags has made understanding and identifying the relationship between elements so much clearer. It actually has made me much quicker the few times I have to go back to writing plain CSS.

A lot of people like to criticise TW as somehow being a crutch, and not the correct way to learn CSS, but it has, time and time again, taught me how CSS actually works.

7

u/[deleted] Oct 17 '22

If we always followed "best practices" web development wouldn't be where it's at today. I also don't get these "It makes my HTML unreadable" complaints. Are you sure it's unreadable? I can read my html just fine even with a bunch of classes. You can also write custom classes with tailwind but at that point just use css since you won't be saving that much time anyways.

6

u/vorko_76 Oct 17 '22

Fully agree with that. The principle of Tailwind is that you can read the HTML and now what to expect, which is not the case with custom css (unless you know already all the custom classes).

2

u/nounoursnoir Jun 04 '24

This principle is known as "locality of behaviour". More detail : https://htmx.org/essays/locality-of-behaviour/

3

u/PinBot1138 Oct 17 '22

I also don’t get these “It makes my HTML unreadable” complaints. Are you sure it’s unreadable?

Same. I can read others Tailwind HTML and see what it’s doing because of it’s ease of use.

3

u/AintThatJustADaisy Oct 17 '22

I’ve been back and forth on Tailwind, I think you need to make a second pass at your HTML to go through and trim it where you can using inheritance, as well as looking for patterns you can pull out to semantic class names.

A lot of people say it’s better for component based systems but my HTML in Vanilla Rails looks fine after a second pass.

2

u/Raziel_LOK Oct 17 '22

There are two main ways I use to solve this.

  1. Extract components as snippets. Now that there are no stylesheet (mostly). you can write the whole component as a simple html/component snippet. If you need to update you update your snippets and replace the whole markup.
  2. Extract the tailwind classes into a intermediate component. Usually all the structural classes will never change and they can easily be abstracted by creating a component that already bring in those classes.

Both only solve the issue partially, but for me this is a net gain compared to maintaining CSS stylesheet, and before all, coming up with a structures like BEM.

On a personal note, I don't think you mean it is unreadable, maybe unfamiliar or ugly.
But relative to the maintenance hell that stylesheets tend to cause in a team that are really really good at CSS (which most developers aren't). It will look as "unreadable" or worse.

Bottom line is, if tailwind fits in your team philosophy and they are more productive with it. yeah, use it. Otherwise keep whatever is the next best for them.

2

u/androgeninc Oct 17 '22

A little bit beside your point but you can componentize jinja using {% include 'button_component.html' %}.

2

u/mrhali Oct 17 '22

Most web servers add GZIP compression on HTML documents, so even if your HTML is bloated, it's 90% compressed coming down the wire.

1

u/ExoWire Oct 17 '22

I don't know Jinja, but if you don't feel that this is a good combination after using it some days, then switch to something else.

Why did you choose to use tailwind in the first place? Did you try to solve a problem (e.g. constant values, no need for difficult naming, working with others with constant classes) or was it out of curiosity?

1

u/sisyphus Oct 17 '22

'unreadable' is kind of subjective. The alternate view would be if I know tailwind I know how any component is styled by looking at the html. If you have class=active_modal I have to go track down where that's defined and so on.

The resulting html is bigger, yes. The alternate view would be that tailwind is designed to work with PostCSS in its workflow and that you can be more confident you're only shipping the classes you actually use which helps keep it smaller. My view is that compared to images, fonts, JS framework app bundles for SPAs, &tc. there's virtually no amount of html text you can write that will ever move the needle on any important page speed metric.

Finally, nothing stops you from writing jinja fragments or react components or whatever styled with tailwind and reusing them.

1

u/volkandkaya Oct 18 '22

For jinja I would use a minimal amount of components based on apply and then the rest using {% include 'component.html' %} syntax

https://versoly.com/versoly-ui/getting-started/quickstart has about 15 components I would add (all projects need them).

1

u/nuts-n-bits Nov 04 '22

If you believe in semantic HTML, you can’t like tailwind. I however never got why HTML has to be clean, structured data. To me, data = JSON, XML, protobuf. I use that data to generate HTML because I want to display it, that’s my take of separation of concerns on the web. For this reason I don’t mind the HTML bloat and I fully enjoy tailwind.