by 9dev · 4mo ago · 0 comments
The conventions and class names come really naturally fast, and you can always look it up. It's just not as a big of a problem people make it.
But the most ridiculous part of the article I found the cascade complaint:
<p class="text-red-500 text-green-500">I am some text</p>
Yes, this does not work. Why should it?! There is not a single use case where this is a good idea! In classic CSS, you might want to override something based on modifier classes, but that is just not a thing with Tailwind! If you end up programmatically layering class names, you're looking at a code smell. Instead, you want to use attribute or state modifiers, like `aria-hidden:opacity-0`.Tailwind seems most useful for devs who don't want to be responsible for managing multiple CSS files and all the naming conventions that come along with it. They're basically looking for using inline styles after having likely heard for a long time to not use the style tag.
For me at least, any value from tailwind went out the window when frameworks started leaning into single file components and scoped styles. I keep components small enough that generally my style selectors are only using element and attribute selectors, I dodge the class naming issue entirely and still get to use CSS instead of inline styles.
If a new dev doesn't know CSS well it won't help them. If a new dev does know CSS but doesn't know Tailwind, it still won't help.
The standardization can be claimed as a benefit, though it really amounts to avoiding having to architect how CSS is managed in a project and at the end of the day the solution is to just inline styles one a time (I.e. no cascade or stylesheets).
Though a bit unrelated, I take issue with the core promise of Tailwind - localization of styles on a node. As soon as flexbox and grid enter the picture I can't simply look at one node and know how it will render. Even more egregious is groups, though a useful feature it breaks locality of styling even worse. Throw in less used but valid syntax for attribute selectors, modifiers, sibling selectors, etc and you might as well be in CSS. Last I used TW it also didn't have an answer for using things like :has() though that could have changed.
This is also my experience. But one of my colleagues highlighted this as a strong feature. He had been doing web dev for many years, but always with a CSS framework. He was really glad that Tailwind forced him to learn plain CSS.
The random outcome, entirely dependent on the Tailwind generation internals, is the worst of all worlds though, it's just an unfortunate side-effect of relying on cascading sheets to drive atomic styles.
Is it ideal? I guess not, but there are a lot of weird gotchas and footguns in CSS too. Just because they’re in the language doesn’t make them magically more or less of a problem. For a similar weird mental shift, consider adding @starting-style and the native popover open attribute. All the good tutorials online have a warning about cascade order because as a human reading it, it can seem wrong or backwards.
Kevin Powell’s most recent video about animating display: none covers it if you want a concrete example.
Sometimes true, but one issue here is that because Tailwind utility classes vary from being a 1:1 mapping to a single underlying style rule, to mapping to several, it's not always obvious which classes will conflict.
Should Tailwind really go out of its way to pay a compile time tax, just to make this case resolve predictably? Or should people rather use code editors that point out invalid duplicated styles, which are always added in error?
Why wouldn't you? Suppose you have Button class with `btn btn-primary`. The Button accepts className override so you can do <Button className='btn-secondary'>. In this case you use tailwind-merge or clsx. Your Button implementation would be clsx('btn btn-primary', className), in which case right most class name prevails.
Other than that, I agree tailwind is great. It lets you keep things all in one place. Names aren't particularly difficult to memorize and reason about and autocomplete does a great job. Build utility classes or proper components to encapsulate the styling and you're fine. What benefit do I have going to a css file to review my button styling over the actual Button component?
Component-based applications are usually better of with no styling cascading and no styling overriding. It makes things significantly easier because components are self contained and don't change in appearance based on styling of parent-elements on the tree (besides physical dimensions available and transparency effects of course).
Document-based applications are usually better of with cascading and overriding. Although no-cascading-no-overriding can work too, but requires more code.
Component-based is quite difficult to do without some tooling (like tailwind or css-modules, etc). Most CSS tooling support both though.
Tailwind implicitly forces you into the component-based paradigm but never explains it properly. There is a reason why people who love tailwind say it just makes things much more manageable. It is mostly because it removes the "mixed" mode that projects silently fall into[1] unless there is some guiding force towards component-based.
However component-based approach is quite doable with many different CSS solutions. Tailwind just _forces_ you into it.
For example CSS-modules component-based just means one .css file per component with only .className {} CSS selectors and not relying on cascading values from above in the tree (a few global rules can solve this).
[1]: Mixed mode as I call it is mixing hyper-local rules with cascading rules. They fall into this mode because that is how plain CSS works without extra tooling and guidelines.
It's a red flag (ha).
Semantic class names make no sense in a component context and that's why tailwind feels like a liberation in the context of component-based web applications. A component and its interface is the semantic meaning, the markup and styles it contains are scoped to that component and should not be / need not be semantic at all. This greatly reduces cognitive load.
author should've instead asked himself & the world - why people are drawn to tailwind. yeah technically it's inferior - but in terms of being optimized for how people do things - tailwind is superior.
One, adding classes from the outside to an encapsulated component with its own, internal classes, to make sure the outside-applied classes take priority. Either use the !important modifier on them (`ms-auto!`), put the components into a container div with the classes for layout concerns, or even better: Figure out why you need to make styling changes to a component that cannot be expressed via props. I would generally recommend components to not have outside-element styling like margins in them anyway, which most often fights with positioning later.
Two, merging prop-derived styling with base styles - for example for a `size: 'sm'|'lg'` prop. It's tempting to just use tailwind-merge here:
const classList = tailwindMerge(
'p-4',
size == 'sm' && 'p-2',
size == 'lg' && 'p-6',
);
But that isn't necessary at all: The better alternative would be to use data attributes for visual concerns and built-in or aria attributes for interaction states. There are almost always element attributes that can represent what you want to have correctly, and data- where there are not. Then, you can just add a class accordingly: <span
class="p-4 data-[size=sm]:p-2 data-[size=lg]:p-6 data-active:font-bold"
data-size={size}
data-active={active}
/>
And you'll end up with easier to maintain components that derive their styles from the CSS cascade alone.It's so common, that there is an expensive runtime package, `tailwind-merge`, that is used by default in the most popular component library.
> 'text-green-500' applies the same CSS properties as 'text-red-500'. tailwindcss(cssConflict)
So even if you do it by accident, it will tell you.
Maybe it helps with people nee to Web development but as an existing CSS developer tailwind slows me down incredibly.
I know exactly what styling I wish to apply, I now have to translate it into another language to apply it.
And the browser inspector looks terrible because every element has a long bunch of utility classes added to it.
And at that point, onboarding a new developer always means wasted time on understanding this whole organically grown set of bespoke conventions, class names, patterns, hierarchies, and so on.
Tailwind does not really have this pattern of deterioration growing along both time and complexity, it stays consistent on both axes. So it's definitely an argument IMHO.
> Out of curiosity how long have you been doing frontend development?
I've been writing CSS since IE 6 and I can tell you not a lot of us oldies like tailwind. I've only seen a strong inclination towards Tailwind from the newer generation frontends (2015 and beyond)
Us oldies actually prefer BEM over anything else.
My talking point is based off internal comms from a large'ish company (200+ FE devs) so YMMV
Would I take it over the 1000 line cascade problems? Probably, but I’d still prefer css modules over tailwind.
> How round is rounded-lg?
Author: "In my vanilla CSS, I can read it in the CSS file. In Tailwind, who knows?!?"
Reality: You read it from location 2, not from location 1. The horror.
I don't even have a dog in the race. I'm past my days of handcrafting HTML and CSS. I have a few Claude Coded apps that use Tailwind, but I've not looked at any of the files (yes yes, I know. They're personal projects that run in my homelab. I don't care.)
There is, as you said, a single place to configure your design system (a CSS file, fwiw), which is objectively better than "well for these card-like containers we usually use 5px everywhere."
Besides, I'm really wondering what sad jokes some people use to edit code that don't even offer tooltips for the styles getting applied by Tailwind classes.