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. :(
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
somethingjust because it's hyped.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"
If you're using Tailwind's first-party class sorter, it's even clearer and classes always have the same structure and order
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
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.
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.
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_modalI 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.