Setup and build
npm install tailwindcss @tailwindcss/cli
Install with the standalone CLI
npm install tailwindcss @tailwindcss/vite
Install the Vite plugin
@import "tailwindcss";
Pull in Tailwind (preflight, theme, utilities)
npx @tailwindcss/cli -i <in> -o <out>
Build the CSS once
npx @tailwindcss/cli -i <in> -o <out>
--watch
Rebuild on change
npx @tailwindcss/cli -i <in> -o <out>
--minify
Minified production build
@source "<path>";
Scan extra files for classes
@source not "<path>";
Exclude a path from scanning
@import "tailwindcss" prefix(tw);
Prefix all utilities (tw:flex)
@import "tailwindcss" important;
Mark every utility !important
Layout
flex-col
Stack children vertically
items-center
Align items on the cross axis
justify-between
Spread items along the main axis
gap-4
Gap between children (1 unit = 0.25rem)
grid grid-cols-3
Three-column grid
col-span-2
Span two grid columns
block / inline-block / hidden
Display values
relative / absolute / fixed / sticky
Positioning
inset-0
Pin to all four edges
overflow-hidden
Clip overflowing content
container mx-auto
Centred, width-capped container
grow / shrink-0
Flex grow and shrink
space-x-4
Horizontal space between children
place-items-center
Centre grid items both ways
Variants
hover:bg-sky-700
On hover
active: / disabled:
Pressed / disabled state
focus-visible:outline-2
Keyboard focus only
sm: md: lg: xl: 2xl:
Min-width breakpoints (40/48/64/80/96rem)
max-md:hidden
Below the md breakpoint
md:max-lg:flex
Only between md and lg
min-[600px]:flex
Arbitrary breakpoint
dark:bg-gray-800
Dark mode
group / group-hover:underline
Style child on parent hover
peer / peer-checked:block
Style by a sibling's state
first: last: odd: even:
Position variants
data-[state=open]:block
Match a data attribute
has-[:checked]:bg-blue-50
Style by a descendant
@container / @md:flex-row
Container query on parent width
disabled:hover:bg-sky-500
Stack variants, left to right
Custom values and theme
bg-[#316ff6]
Arbitrary colour
grid-cols-[24rem_1fr]
Underscore stands for a space
bg-(--my-var)
Use a CSS variable
[--gap:1rem]
Set a CSS variable via a class
bg-red-500!
Important modifier (trailing !)
@theme { --color-brand: #f00; }
Add a design token (bg-brand)
@theme { --breakpoint-sm: 30rem; }
Override a default value
@theme { --color-*: initial; }
Drop a whole namespace
@theme inline { --font-sans: var(--x); }
Token that references another variable
@apply <utilities>;
Inline utilities into your own CSS
@utility <name> { ... }
Define a custom utility
@custom-variant dark (&:where(.dark, .dark *));
Class-based dark mode
@plugin "@tailwindcss/typography";
Load a plugin
@reference "<css>";
Use theme/@apply in a Vue/Svelte style block
@layer components { ... }
Put custom CSS in a layer