Am I Wrong about @apply? #7651
Replies: 3 comments 7 replies
-
Hey! I’ve written about this quite a bit in the docs: https://tailwindcss.com/docs/reusing-styles#avoiding-premature-abstraction The way Tailwind is intended to be used is as utility classes directly in your HTML. Making a distinction between development and production I think is a bad idea — raw utility classes are by far easier to maintain than custom classes created with Happy to answer any other questions 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
I tend to use After a couple of projects I think the advice makes a lot of sense, but I was also really overthinking it at the start. I'm not afraid to leave a few |
Beta Was this translation helpful? Give feedback.
-
I really like the
You can immediately see what that is and your HTML code stays nice and short. VS something like this which your brain has to process:
When you have a dozen or more utility classes this type of grouping is so much easier to reason with. I also hate code polluted with inline classes. To me the class name can actually help guide you as to what the element is.
is so much more rational in my brain than this:
You know immediately that's an icon for a button. Yes in most cases you would have a separate component for this making it obvious. But that's not always possible when using other people's libraries. Finally you're always going to have some duplication that components aren't going to solve for you. Maybe you want to have a consistent padding or margin or text style (size, line height, font, etc) for similar but different components that can't be children of the same parent. Do people use variables for this if not using apply? I made the mistake of typing this on a phone so sorry for any obvious formatting issues |
Beta Was this translation helpful? Give feedback.
-
I've talked to a lot of people about the use of @apply and I think it's the magic sauce of the library. But others think it's an anti-pattern. Here's my take:
I am curious others opinions (especially @adamwathan and other authors of Tailwind). Since I teach tailwind, I'd love to know if I am wrong and how I am wrong.
Beta Was this translation helpful? Give feedback.
All reactions