At some point, you should abstract some set of classes. In some cases, CSS selectors and other CSS feature will allow you to do what you want with far fewer lines of code.
[1]: https://twitter.com/xirclebox/status/1673557143088242689
At some point, you should abstract some set of classes. In some cases, CSS selectors and other CSS feature will allow you to do what you want with far fewer lines of code.
[1]: https://twitter.com/xirclebox/status/1673557143088242689
https://tailwindcss.com/docs/reusing-styles#extracting-class...
I'd also add that the code in the Tailwind example is much easier to maintain and jump in on. It describes everything going on without you having to cross-reference a separate CSS doc with all of the actual meaning hidden in it. Joining a new project with 1000+ line CSS files + media queries randomly added throughout is a horrendous experience.
Because that's the context where Tailwind grew.
If you have your set of e.g. React components defined you don't really ever "repeat the same styles for links, buttons again and again". You just use your components. <Button/>. <Link/>. <Card/>. <Container/>. Whatever you need. And then your only "raw" tailwind in your "templates" is the scaffolding around it.
And it's great. No write-only CSS syndrome, no coupling between components, at-glance understandability of what's going on.
But you gotta be using components, otherwise it's just overwhelming.
What I actually like about Tailwind is not that you don't have to create classes at all, it's that you don't have to do it for things that don't need it. My old codebase was littered with hundreds of classes doing the same set of styling — padding, margins, flex-box stuff. That's the biggest thing Tailwind helps with.
To say "proper classes" doesn't imply anything about CSS. Classes are a markup concept. The class attribute predates CSS; CSS's selector language lets you target "classified" content, but it's not like classes were invented for CSS.
What's "proper classes and such"? You mean hundreds of increasingly specific and non-reusable BEM abominations like `.hero-text__sticky-container--secondary` that no one remembers and creates new ones?
I've yet to see a single project to not devolve into a mess of class names. Not only that, but a mess of class names with significantly repeating boilerplate, intimately tied to specific elements.
* or `hero text`, even (sans hyphen)
[1]: [link redacted]
You extract those into components, and use them as components
I've been on a project like that, and the result was maddening: any page or component template would contain only references to other components and almost no plain HTML tag.
Each time you encountered something like a 'Title' or a 'Button' or a 'FooBarHeader' component, you didn't knew how much Javascript was executed behind each of those, or wether it had any side effects until you looked at the code (and sometime had nasty surprise on components used everywhere).
You also either had to look at its API or modify it to correctly use the web plateform (eg: how do I specify to my 'Button' is of type="button" or of type="submit" ? How do I add some aria attributes ? What if I want to add a 'data' attribute ?).
On top of that, the generated, runtime DOM would look nothing like the design-time template you are changing, which goes against the plateform, again.
And you also ended up with a huge 'components' surface, where this moderately complex (in term of essential complexity) had more than a hundred components, with some basic 'Button' component being monstruous 500+ lines of code under the hood (because of CSS-in-JS), all of it destroying the performance of the page.
On this particular project, I realized that the tag-to-component ratio was less than 1, even maybe closer to 0 than 1. In other words, behind each little <span> visible in the inspector, you had something like 3 to 5 component instances. I've called it "loosing your footing", as you couldn't touch any primitive, drowning in a sea of abstraction.
Somehow, I feel that it's more specific to the 'React' world which is a bit too trigger happy when it come to creating new component.
The entire history of CSS is about the struggle to create components: from BEM to Sass and nested CSS. Separation of concerns cuts both ways: https://twitter.com/simonswiss/status/1664736786671869952?s=...
https://tailwindcss.com/docs/reusing-styles#avoiding-prematu...
Plus, I'd assume that almost everyone using Tailwind is going to break their website/app into reusable components - which negates the need to use @apply across the board.