npm install tailwindcss @tailwindcss/vite★The Vite plugin is the recommended path. Add it invite.config.js:import tailwindcss from "@tailwindcss/vite"→plugins:[tailwindcss()]. Massively faster than v3./* your main .css file — this ONE line replaces v3's three directives */ @import "tailwindcss";★Everything comes from a single import — no more@tailwind base/components/utilities. ⚠️ v4 auto-detects your template files, so there's nocontentarray to configure.# PostCSS instead: npm i @tailwindcss/postcss → postcss.config # CLI instead: npx @tailwindcss/cli -i in.css -o out.css --watchNot on Vite? Use the PostCSS plugin (@tailwindcss/postcss) or the standalone CLI. Same@importin all three.<div class="flex items-center gap-4 p-6 bg-white rounded-lg shadow">★The whole idea: compose small single-purpose utilities inclass. No separate CSS file to maintain, no naming things.
@import "tailwindcss"; @theme { --color-brand: oklch(0.62 0.19 260); --font-display: "Satoshi", sans-serif; --breakpoint-3xl: 120rem; }★Configure the design system in CSS via@theme— this is the headline v4 change. Each token both sets a CSS variable and generates utilities./* the token above auto-creates: */ bg-brand text-brand font-display 3xl:*★Define--color-brand→ getbg-brand,text-brand,border-brand, etc. for free. Namespaces:--color-*,--font-*,--spacing-*,--breakpoint-*,--radius-*, ….hero { background: var(--color-brand); } /* tokens are real CSS vars */Every theme value is exposed as a native custom property at runtime — use them in hand-written CSS, inline styles, or JS.--spacingdrives the whole numeric scale.@import "tailwindcss" prefix(tw); /* → tw:flex tw:p-4 */Need a prefix (e.g. embedding in another app)? Set it on the import. A JS config is still supported via@config "./tailwind.config.js";when you need it.
flex items-center justify-between gap-4★Flexbox essentials:flex/flex-col, align on the cross axis (items-*), distribute on the main axis (justify-*), andgap-*for spacing between children.grid grid-cols-3 gap-6 · col-span-2 row-span-1★CSS Grid: fixed tracks withgrid-cols-N, place items withcol-span-*/col-start-*. Combine with responsive prefixes for adaptive layouts.relative absolute inset-0 top-4 z-10 · hidden block inline-flexPositioning (relative/absolute/sticky+inset/top/left+z-*) and display utilities.containercenters & caps width at each breakpoint.<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">★The bread-and-butter responsive grid — one column on mobile, widening at each breakpoint. This composition is most of real-world layout.
p-4 px-6 pt-2 m-4 mx-auto -mt-2★Padding/margin:p/m+ side (t r b l,x,y) + step.mx-autocenters a fixed-width block; negative margins with a-prefix.w-64 h-screen min-w-0 max-w-prose size-10★Sizing:w-*/h-*(fixed,full,screen,dvh, fractions likew-1/2), plusmin-/max-.size-*sets width & height together.space-y-4 /* margin between stacked children */space-x/y-*adds gaps between siblings without touching the parent's own padding — handy whengapdoesn't apply (non-flex/grid)./* the scale is 0.25rem × n: p-4 = 1rem = 16px. one token drives it all */Every step iscalc(var(--spacing) * n). Change--spacingonce in@themeand the entire scale rescales consistently.