@apply
@apply
:
.custom-card
,
.custom-card-header
, and
.custom-card-body
classes defined with
@apply
.
The HTML is less verbose for this specific component.
bg-white
,
shadow-xl
,
p-6
) from the HTML. You need to check the CSS to see the actual styles.
bg-white
,
shadow-xl
,
p-6
, etc.) is present in the HTML, aligning with the utility-first approach.
@apply
:
The "Gotcha" with
@apply
is that overusing it can lead you back towards a more traditional CSS workflow.
While it's handy for small, truly reusable utility-like abstractions (e.g., a consistent button style),
creating many complex component classes with
@apply
can:
Recommendation: For larger applications or complex, reusable UI elements, building true components with a JavaScript framework (like React, Vue, Svelte, or Angular) is generally preferred. These components can encapsulate markup and use Tailwind's utility classes directly within them, offering better structure and maintainability than heavy
@apply
usage.
Use
@apply
judiciously for small, self-contained utility-like abstractions where the benefits of DRY (Don't Repeat Yourself) outweigh the loss of direct utility visibility in the HTML.