What is Tailwind CSS?
Tailwind CSS is a utility-first framework. Instead of writing custom CSS classes, you compose small, single-purpose classes directly in your HTML.
The Idea
Traditional CSS:
.card {
padding: 1rem;
border-radius: 0.5rem;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
<div class="card">Hello</div>
Tailwind:
<div class="p-4 rounded-lg bg-white shadow">Hello</div>
Each class does one thing: p-4 is padding, rounded-lg is a border radius, shadow is a shadow.
Why Utility-First?
- No naming — You never invent
.card-header-inneragain. - No dead CSS — Classes you do not use are not generated.
- Consistent scale — Spacing, colors, and sizes come from one design system.
- Local reasoning — The styles are right there in the markup.
A Real Component
<button
class="rounded-lg bg-blue-600 px-4 py-2 font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400"
>
Save
</button>
Hover, focus, color, spacing — all visible at a glance.
Does It Get Verbose?
It can, for complex elements. Tailwind gives you tools for that:
- Components — Extract repeated markup into a component.
@apply— Compose utilities into a named class when needed.clsx/cva— Build conditional class strings cleanly.
Verbosity in markup usually beats a tangle of overlapping stylesheets.
Tailwind vs Plain CSS
| Plain CSS | Tailwind |
|---|---|
| You name every class | Utilities are pre-named |
| CSS grows forever | Only used utilities ship |
| Global cascade surprises | Scoped to the element |
| Design system is on you | Built-in scale |
Best Practices
- Think in utilities — Compose, do not fight it.
- Extract components, not classes — Reuse markup, not stringly-typed CSS.
- Stay on the scale —
p-4, not arbitraryp-[13px]without reason. - Use the docs — The class search is the fastest way to learn.
Common Mistakes
- Treating utilities as inline styles — They are a design system, not free-form CSS.
- Overusing arbitrary values —
w-[137px]everywhere defeats consistency. - Copy-pasting long class lists — Extract a component.
- Skipping
hover/focusstates — They are built in; use them.