When the same utility chain appears everywhere, extract it:
- Framework component — React/Vue/Svelte props (preferred in apps)
- @apply in CSS — bundle utilities into
.btn-primaryin a layer - Partial templates — Blade, ERB, or includes for static sites
@apply guidelines
Use @apply for truly repeated primitives (buttons, badges), not entire pages. Over-extraction hides Tailwind’s benefit and reintroduces naming debates.
.btn-primary {
@apply rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700;
}
Important interview questions and answers
- Q: @apply vs component?
A: Components add props and logic; @apply is CSS-only extraction for design primitives. - Q: Why do some teams ban @apply?
A: It can produce larger CSS and obscure markup; they prefer colocated utility strings or UI components.
Self-check
- When is a React component better than @apply?
- What is one risk of @apply-heavy codebases?
Interview prep
- When is @apply appropriate?
Sparingly—for third-party widgets or legacy CSS files; prefer utilities in components for most app UI.