Efficiently Usage of Tailwind
2 min read 👋

Efficiently Usage of Tailwind

Lwin Moe Paing

written by

Lwin Moe Paing

Founder of Erudite

Updated on Jan 15, 2026

Tailwind CSS has become one of the most popular CSS frameworks for modern web development. But are you using it efficiently? In this article, we'll explore patterns and techniques that will help you write cleaner, more maintainable Tailwind code.

Why Utility-First Works

The utility-first approach might feel verbose at first, but it eliminates the need for context-switching between HTML and CSS files. Every style is right where you need it.

Tip

Use the cn() utility from clsx + tailwind-merge to conditionally combine classes without conflicts.

Custom Theme Configuration

One of Tailwind's most powerful features is the @theme directive in v4. You can define your design tokens directly:

@theme {
--color-primary: #00a6f0;
--color-background: #0f0f0f;
--font-title: "OldschoolGrotesk", sans-serif;
}

This replaces the old tailwind.config.js approach and keeps everything in CSS.

Component Patterns

When you find yourself repeating the same set of utilities, extract them into a component — not a CSS class:

Good: Extract a component
function Badge({ children }: { children: React.ReactNode }) {
return (
<span className="rounded-full bg-primary px-3 py-1 text-sm text-white">
{children}
</span>
);
}
Warning

Avoid @apply in Tailwind v4. It defeats the purpose of utility-first and makes refactoring harder.

Performance Tips

  1. Purge unused styles — Tailwind v4 does this automatically via content detection
  2. Use arbitrary values sparinglyw-[137px] is a code smell; check if a design token fits
  3. Leverage responsive prefixesmd:grid-cols-3 is better than media query CSS

Conclusion

Tailwind CSS is a powerful tool when used correctly. Focus on components over @apply, use the theme system for design tokens, and let the framework handle the rest.