Quick Reference Tailwind CSS Cheatsheet
Tailwind v4 on one page — setup, the spacing scale, layout, flex and grid, type, color,
borders and shadows, responsive and state variants, theme tokens, and the class-name traps
that show up in reviews.
10 sections 9 tables 17 code snippets 🚀 Install & First Classes Vite + Tailwind v4 npm install tailwindcss @tailwindcss/vite
Global CSS @import "tailwindcss"; A button <button class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700">
Save
</button> Utilities are the API. You style in the markup, and Tailwind generates only the CSS for classes it finds. v4 discovers files automatically. You do not list content paths unless a folder is being skipped. 📏 Spacing, Sizing & the Scale Padding, margin, size <div class="mx-auto mt-8 max-w-3xl px-4 py-6">
<div class="h-16 w-16"></div>
<div class="size-10"></div>
</div> The number is a step on a 0.25rem scale, not pixels. 4 means 4 steps, so 1rem. Negative margin is -mt-4. Arbitrary values look like w-[32rem] or top-[13px]. 🧱 Display, Position & Overflow Display and position <div class="relative">
<span class="absolute top-2 right-2">New</span>
<img class="block h-auto w-full" alt="" />
</div> Row with space between <header class="flex items-center justify-between gap-4">
<h2 class="text-lg font-semibold">Courses</h2>
<a class="text-sm text-indigo-600" href="/courses">All</a>
</header> Responsive card grid <ul class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<li class="col-span-1 rounded-xl border p-4">Card</li>
</ul> A heading and a paragraph <h1 class="text-3xl font-bold tracking-tight text-slate-900 sm:text-5xl">
Learn. Practice. Conquer.
</h1>
<p class="mt-3 text-base leading-relaxed text-slate-600">
Short lessons with practice on every page.
</p> 🎨 Color, Background & Opacity Text and surface <article class="bg-white text-slate-800 dark:bg-slate-950 dark:text-slate-100">
<p class="text-indigo-600">Label</p>
<div class="bg-indigo-600/10"></div>
</article> How a color class is built v4 gradient utilities are bg-linear-to-r, bg-radial, and bg-conic. The older bg-gradient-to-r name is the v3 spelling. ▢ Borders, Radius, Shadow & Rings A card <div class="rounded-xl border border-slate-200 bg-white p-6 shadow-sm">
<h3 class="font-semibold">Java</h3>
</div> Focus ring <input class="w-full rounded-lg border px-3 py-2 outline-hidden focus:border-indigo-500 focus:ring-2 focus:ring-indigo-500" /> 📱 Responsive, Hover, Dark & Focus Mobile first <section class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4">
<a class="underline-offset-4 hover:underline focus-visible:ring-2" href="/gate">
GATE
</a>
</section> Group hover <a class="group block" href="/java">
<h3 class="group-hover:text-indigo-600">Java</h3>
</a> Stack variants left to right: dark:md:hover:bg-slate-800. The breakpoint does not mean “only on small screens.” Unprefixed classes already apply there. 🎛️ Theme, Arbitrary Values & @apply Design tokens in CSS @import "tailwindcss";
@theme {
--color-brand: #4f46e5;
--font-sans: "Inter", sans-serif;
--breakpoint-3xl: 120rem;
} Use the token <p class="bg-brand font-sans text-white 3xl:text-xl">
Brand
</p> What `--` namespaces create Prefer utilities in HTML. Use @apply only inside a component class you truly repeat. A dynamic name such as ` bg-${color}-500 ` is invisible to the scanner, so the CSS is never generated. Write the full class name. Keep every class complete const tones = {
info: "bg-sky-50 text-sky-800",
danger: "bg-red-50 text-red-800",
};
<span class={tones[tone]}>Note</span> Let a flex child shrink <div class="flex">
<p class="min-w-0 flex-1 truncate">
A long title that should ellipsize
</p>
</div> How to use this page: skim the jump chips, then restyle one card using only utilities: spacing, a responsive grid, type, a border, and a hover: plus focus-visible: state. If a class does nothing, the name was probably built with string concatenation. |