| |

Tailwind CSS 81 🎨 Cheatsheet

⏱️ Estimated read: 4 min | |

Tailwind CSS is a utility-first CSS framework that provides low-level utility classes for building custom designs directly in your markup, without writing custom CSS . Version 4 represents a ground-up rewrite: the new Oxide engine built in Rust delivers up to 10x faster builds, configuration moves from JavaScript to CSS with the @theme directive, and content detection is now automatic . The framework requires Safari 16.4+, Chrome 111+, and Firefox 128+; older browsers need Tailwind v3 .

This cheatsheet covers the v4 syntax, the directive-based configuration model, the core utility categories, and the breaking changes that matter when migrating from v3. It assumes familiarity with HTML and basic CSS concepts.

Key point: Tailwind v4 replaces the three @tailwind directives with a single @import "tailwindcss" and moves configuration from tailwind.config.js into CSS via @theme. The content array is gone—Tailwind scans your project automatically, respecting .gitignore.


Installation and Setup

/* v4: single import replaces @tailwind base/components/utilities */
@import "tailwindcss";
SetupCommand/ConfigNotes
Vite (recommended)@tailwindcss/vite pluginFastest option
PostCSS@tailwindcss/postcssStandard integration
CLInpx @tailwindcss/cliStandalone builds
// vite.config.ts — first-party Vite plugin
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({ plugins: [tailwindcss()] });

Automatic content detection means no content array. To include external sources, use @source "../node_modules/ui-lib" .


Core Directives (v4)

DirectivePurposeExample
@import "tailwindcss"Load all of TailwindRequired at top
@themeDefine design tokens as CSS variables--color-brand: oklch(...)
@sourceAdd files outside auto-detection@source "../ui-lib"
@utilityRegister custom utility@utility tab-4 { tab-size: 4 }
@variantApply variant inside CSS@variant dark { ... }
@custom-variantDefine new variant@custom-variant theme-midnight (...)
@applyInline utilities into custom CSS@apply rounded-lg shadow
@referenceImport theme without duplicating CSSRequired in Vue/Svelte <style>

Layout Utilities

CategoryClassesExample
Displayblock, inline, flex, grid, hiddenflex items-center
Flex directionflex-row, flex-colflex flex-col md:flex-row
Justifyjustify-start, justify-center, justify-betweenflex justify-between
Align itemsitems-start, items-center, items-stretchflex items-center
Gapgap-4, gap-x-2, gap-y-6grid gap-6
Grid columnsgrid-cols-1 to grid-cols-12grid grid-cols-1 md:grid-cols-3
Positionrelative, absolute, fixed, stickyabsolute inset-0
Insetinset-0, top-4, inset-s-4 (logical)absolute inset-s-4

Spacing and Sizing

CategoryClassesNotes
Paddingp-4, px-6, py-2, pt-8Spacing scale: p-4 = 1rem
Marginm-4, mx-auto, mt-8, -mt-2Negative values supported
Space betweenspace-x-4, space-y-2Between children
Widthw-full, w-1/2, w-64, w-screenv4 adds inline-* for logical width
Heighth-full, h-screen, h-32block-* for logical height
Min/Maxmin-w-0, max-w-md, max-h-screenmax-w-7xl common container
Sizesize-8Shorthand for w-8 h-8

Typography

CategoryClassesExample
Font sizetext-sm, text-base, text-xl, text-4xltext-2xl font-bold
Font weightfont-light, font-normal, font-semibold, font-boldfont-semibold
Text colortext-gray-900, text-blue-500, text-red-600text-muted-foreground
Text aligntext-left, text-center, text-righttext-center
Line heightleading-none, leading-tight, leading-relaxedleading-relaxed
Letter spacingtracking-tight, tracking-widetracking-wide
TruncatetruncateEllipsis overflow

Backgrounds, Borders, and Effects

CategoryClassesNotes
Backgroundbg-white, bg-gray-100, bg-blue-500v4 palette uses OKLCH
Border widthborder, border-2, border-t-4v4 border defaults to currentColor
Border colorborder-gray-300, border-transparentExplicit color needed in v4
Border radiusrounded-sm, rounded-md, rounded-fullv4 renamed scales
Shadowshadow-sm, shadow-md, shadow-lgv4 renamed scales
Ringring-2, ring-blue-500Focus rings
Opacityopacity-50, opacity-100
Blurblur-sm, blur-mdv4 renamed scales

Responsive and Variants

Tailwind is mobile-first: unprefixed classes apply at all widths; prefixed classes apply from the breakpoint up .

PrefixMin widthCSS
sm:40rem (640px)@media (width >= 40rem)
md:48rem (768px)@media (width >= 48rem)
lg:64rem (1024px)@media (width >= 64rem)
xl:80rem (1280px)@media (width >= 80rem)
2xl:96rem (1536px)@media (width >= 96rem)

State variants: hover:, focus:, active:, disabled:, group-hover:, peer-focus:, dark:, motion-safe:, motion-reduce:.

<button class="bg-blue-500 hover:bg-blue-700 focus:ring-2 focus:ring-blue-300 disabled:opacity-50">

Container queries (v4 core): mark parent with @container, style children with @sm:, @md:, etc. .


Breaking Changes from v3

v3v4Notes
@tailwind base/components/utilities@import "tailwindcss"Single import
tailwind.config.js@theme in CSSCSS-first config
content: [...]Automatic detectionRespects .gitignore
shadow-smshadow-xsRenamed scales
rounded-smrounded-xsRenamed scales
blur-smblur-xsRenamed scales
outline-noneoutline-hiddenAccessibility distinction
bg-left-topbg-top-leftConsistent naming
Default border graycurrentColorExplicit border color needed

Common Pitfalls

PitfallFix
Using v3 @tailwind directivesReplace with @import "tailwindcss"
Expecting content array to workDelete it; v4 auto-detects
Border color invisiblev4 defaults to currentColor; add border-gray-300
Old shadow/radius class namesCheck v4 rename table
@apply in Vue/Svelte <style> failsAdd @reference "../app.css"
Using start-*/end-*Deprecated; use inset-s-*/inset-e-*

Visual: v4 Architecture

┌──────────────────────────────────────────────┐
│  TAILWIND V4 PIPELINE                        │
│                                              │
│  @import "tailwindcss"                       │
│       │                                      │
│       ▼                                      │
│  Oxide engine (Rust)                         │
│       │                                      │
│       ├── Auto content detection             │
│       ├── @theme tokens → CSS variables      │
│       └── Utility generation                 │
│       │                                      │
│       ▼                                      │
│  Static CSS (purged)                         │
│                                              │
│  No tailwind.config.js required.             │
│  Design tokens live in CSS.                  │
│  Builds up to 10x faster.                    │
│                                              │
└──────────────────────────────────────────────┘

Summary

AreaKey Takeaway
Import@import "tailwindcss" (single directive)
Config@theme in CSS; no tailwind.config.js needed
ContentAutomatic detection; @source for external
BreakpointsMobile-first: sm: 640px, md: 768px, lg: 1024px
Variantshover:, focus:, dark:, group-hover:, peer-focus:
Container queries@container on parent, @sm: on children
v4 renamesshadow-sm→shadow-xs, rounded-sm→rounded-xs
Border defaultcurrentColor; specify explicit color
Custom utility@utility name { ... }
Custom variant@custom-variant name (...)

Tailwind v4 is a CSS-first framework. The @theme directive replaces the JavaScript config, the @utility and @custom-variant directives replace plugin configuration, and the Oxide engine makes builds fast enough that the configuration model change is not the only reason to upgrade. The breaking changes are mostly renames—shadows, radii, blurs, and the border default—and the official upgrade tool (npx @tailwindcss/upgrade) handles most of them automatically . For the full utility list, the official documentation and the community cheat sheet extensions cover 5,500+ utilities across 90+ variants .

Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!