Cheatsheet

Cheatsheet — Tailwind CSS

Decision rules

SituationDo thisWhy
New reusable design token@theme { --color-brand: ...; }Auto-generates the matching utility
One-off value, no reusable token neededbg-[#316ff6] (arbitrary value)Skips polluting the theme for a single use
Token value is var(...) referencing another variable@theme inline { --font-sans: var(--font-inter); }Plain @theme can resolve to the wrong scope
Full-viewport height on mobilemin-h-dvh, not min-h-screenvh/screen misbehaves under mobile browser chrome
Style a component by its own size, not the page@container + @sm:Portable across sidebar/main/modal placements
Style based on descendant's statehas-checked:, or group+group-has-checked: on an ancestorNo JS state tracking needed
Style based on a later sibling's statemark earlier element peer, target with peer-*:peer must precede the styled element in the DOM
Two utilities would target the same CSS propertyBranch the class string, never apply bothCascade order (not class order) decides the winner
Multi-line truncationline-clamp-<n>No JS, no manual height + overflow hack
Single-line truncationtruncateShorthand for overflow-hidden text-overflow-ellipsis whitespace-nowrap
Icon should match surrounding text colorfill-current/stroke-currentRecolors via the parent's text-*, not per-icon overrides
Frosted-glass panelbackdrop-blur-* + a translucent bg-*/<opacity>backdrop-filter needs transparency to be visible
Shadow on a transparent PNG/icondrop-shadow-*, not box-shadowFollows the alpha shape, not the bounding box
Disable Preflight for legacy integrationImport theme.css+utilities.css, skip preflight.cssDocumented, supported integration path
Migrating v3 → v4npx @tailwindcss/upgrade, review diffHandles most mechanical renames automatically

Responsive & container-query breakpoints

PrefixMin-widthPrefixMin-width
sm:640px@3xs256px
md:768px@xs320px
lg:1024px@sm384px
xl:1280px@md448px
2xl:1536px@lg@7xl512px…1280px

max-{bp}: applies below that breakpoint; stack {bp}:max-{bp2}: for a range. Same pattern with @ for container queries.

Spacing/sizing value grammar (applies across margin/padding/width/height/gap/inset/...)

SuffixResolves to
-<number>calc(var(--spacing) * <number>)
-<fraction>calc(<fraction> * 100%)
-px1px
-full100%
-autoauto (margin/width/height only, not padding/max-*)
-(<custom-property>)var(<custom-property>)
-[<value>]literal arbitrary value

Default --spacing = 0.25remp-4 = 1rem = 16px.

Common variant prefixes

PrefixMeaning
hover: focus: active:Interaction pseudo-classes
disabled: invalid: checked:Form-state pseudo-classes
first: last: odd: even: nth-<n>:Structural position
has-*:Based on own descendants
group-*: / peer-*:Based on a marked ancestor / earlier sibling
not-*:Negates any other variant
dark:prefers-color-scheme: dark (overridable)
motion-reduce: motion-safe:prefers-reduced-motion
aria-*: data-*:Attribute-based (headless UI state)
rtl: ltr:Text direction
starting:@starting-style (entry transitions)
supports-[...]:@supports feature query
*: / **:Direct children / all descendants

v3 → v4 renames worth memorizing

v3v4
shadow-sm/shadowshadow-xs/shadow-sm
blur-sm/blurblur-xs/blur-sm
rounded-sm/roundedrounded-xs/rounded-sm
outline-noneoutline-hidden (new outline-none really means outline-style:none)
ring (3px, blue-500)ring-3 + explicit ring-<color> (1px, currentColor default)
@tailwind base/components/utilities@import "tailwindcss";
Leading !util importantTrailing util!
bg-[--var]bg-(--var)