Using class names in HTML vs using @apply in SCSS #4216
Replies: 1 comment 3 replies
-
The best practices is the opposite of what you suggest. Having a class named You may think you are making things shorter by using Instead what is recommended is to use components so that you don't need to repeat yourself. Personally I use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all!
I really appreciate the work that has been put into Tailwind and even though I'm just getting started, it seems amazing!
I just wanted to ask tips from the community.
We can apply styles using the Tailwind class names by adding required classes to the HTML elements, or in our SCSS file, we can select the element(s) and use
@apply
. So far so good. I am just wondering what are the best practices when it comes to the following:Consider a case where I want to style the
<header>
element. Considering there's going to be just one such element on the entire page, would it be better applying styles in the markup or by using@apply
in SCSS? I'm talking in regards to the final production bundle size. Are there any considerations I should keep in mind before just applying styles using@apply
to a large number of elements?I'm asking this because in my current setup, I have added a lot of classes to many elements and my HTML is looking kinda unreadable to me. Thus, I was planning to keep styles in the SCSS itself. But if that's not a good thing to do, let me know.
Beta Was this translation helpful? Give feedback.
All reactions