What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework: instead of writing custom class names and stylesheets, you compose small single-purpose classes directly in your markup, like flex items-center gap-4 rounded-lg bg-blue-600 px-4 py-2 text-white hover:bg-blue-700. A build step scans your files and generates only the CSS you actually use.

Key concepts

  • Utilities map to one or a few declarations: p-4 (padding 1rem), text-sm, grid-cols-3.
  • Variants as prefixes: responsive (md:grid-cols-2), states (hover:, focus-visible:, disabled:), dark mode (dark:), group and peer (group-hover:), has-[…]:, container queries (@md:).
  • Design tokens: a consistent scale for spacing, colors and typography. In Tailwind v4, tokens are configured in CSS with @theme and become CSS variables.
  • Arbitrary values: w-[37rem], bg-[#2b4bff] for one-offs.

Pros

  • Very fast to build and iterate; no context switching or naming.
  • Consistency from a shared scale.
  • Tiny CSS bundles that stop growing: utilities are reused across the whole app.
  • No dead CSS and no specificity battles; styles are local to the markup.
  • Works well with component frameworks and Server Components (no runtime).

Cons

  • Long class lists can hurt readability (mitigate with components, clsx/cn helpers, and Prettier's class sorting plugin).
  • Learning the vocabulary.
  • Repeated patterns need extraction into components.

Ecosystem

shadcn/ui, Headless UI and Radix pair with Tailwind for accessible components.

Interview tip

Address the "inline styles" criticism: unlike inline styles, Tailwind supports states, media queries and design constraints.

Code example

html
1<!doctype html>
2<html lang="en">
3<head>
4 <meta name="viewport" content="width=device-width, initial-scale=1">
5 <script src="https://cdn.tailwindcss.com/3.4.16"></script>
6</head>
7<body class="bg-amber-50 p-6 font-sans text-slate-900">
8 <div class="grid gap-4 sm:grid-cols-2">
9 <article class="group rounded-xl border-2 border-slate-900 bg-white p-4 shadow-[4px_4px_0_#0b1020] transition hover:-translate-y-0.5">
10 <h2 class="text-lg font-extrabold group-hover:text-blue-600">Utility-first</h2>
11 <p class="mt-1 text-sm text-slate-600">Styles composed from small classes.</p>
12 <button class="mt-3 rounded-lg bg-blue-600 px-4 py-2 font-bold text-white hover:bg-blue-700 focus-visible:outline focus-visible:outline-4 focus-visible:outline-yellow-300">
13 Get started
14 </button>
15 </article>
16 <article class="rounded-xl border-2 border-slate-900 bg-yellow-200 p-4">
17 <h2 class="text-lg font-extrabold">Responsive</h2>
18 <p class="mt-1 text-sm">One column on phones, two from the <code>sm</code> breakpoint.</p>
19 </article>
20 </div>
21</body>
22</html>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app