Spacing: padding, margin and gap
Spacing classes multiply --spacing (0.25rem by default) by their number, so p-4 is 1rem and any whole number works.
| What it does | Class |
|---|
| Padding on all sides | p-4 |
| Horizontal and vertical padding | px-6 py-2 |
Padding on one side (pt, pr, pb, pl) | pt-8 |
| Padding at the start and end of the line (flips in right-to-left) | ps-4 pe-2 |
| Margin on all sides | m-4 |
| Center a block horizontally | mx-auto |
| Negative margin | -mt-2 |
| Vertical space between children | space-y-4 |
| Gap between flex or grid items | gap-4 |
| Different column and row gaps | gap-x-8 gap-y-4 |
| One pixel, or zero | p-px m-0 |
| An exact value | mt-[13px] |
Sizing: width and height
| What it does | Class |
|---|
| Width from the spacing scale | w-64 |
| A fraction of the parent's width | w-1/2 |
| Full width of the parent | w-full |
| Width and height at once | size-10 |
| Height | h-12 |
| Full viewport height, mobile-safe | h-dvh |
| At least the viewport's height | min-h-screen |
| Minimum and maximum width | min-w-0 max-w-md |
| A readable line length for text | max-w-prose |
| As wide as the content | w-fit |
| Aspect ratio | aspect-video |
| An exact width | w-[350px] |
Typography
| What it does | Class |
|---|
Font size (text-xs to text-9xl) | text-lg |
| Font size with a line height | text-lg/7 |
| Font weight | font-semibold |
| Font family | font-mono |
| Line height | leading-relaxed |
| Letter spacing | tracking-tight |
| Align text | text-center |
| Align to the start of the line (follows the text direction) | text-start |
| Uppercase | uppercase |
| Italic and underlined | italic underline |
| Underline offset and thickness | underline-offset-4 decoration-2 |
| Cut one line with an ellipsis | truncate |
| Limit text to three lines | line-clamp-3 |
| Balance the lines of a heading | text-balance |
| Break long words to avoid overflow | wrap-break-word |
| Keep text on one line | whitespace-nowrap |
| Bulleted list | list-disc list-inside |
Colors
Every palette color has shades from 50 to 950, defined in OKLCH.
| What it does | Class |
|---|
| Text color | text-gray-700 |
| Background color | bg-sky-500 |
| Border color | border-red-300 |
| A color at 50% opacity | bg-black/50 |
| An exact color | bg-[#1da1f2] |
| A color from a CSS variable | bg-(--brand) |
| Use the current text color | border-current |
| Transparent background | bg-transparent |
| White text on black | text-white bg-black |
| Placeholder text color | placeholder:text-gray-400 |
| Selected text color | selection:bg-yellow-200 |
| Caret and form accent color | caret-pink-500 accent-pink-500 |
| SVG fill and stroke | fill-blue-500 stroke-white |
Backgrounds and gradients
| What it does | Class |
|---|
| Linear gradient from left to right | bg-linear-to-r from-cyan-500 to-blue-500 |
| Gradient with a middle color | from-indigo-500 via-purple-500 to-pink-500 |
| Gradient at an angle | bg-linear-45 |
| Where the gradient stops | from-10% to-90% |
| Radial gradient | bg-radial |
| Conic gradient | bg-conic |
| Background image | bg-[url(/hero.jpg)] |
| Cover the element and center the image | bg-cover bg-center |
| Do not repeat the image | bg-no-repeat |
Flexbox
| What it does | Class |
|---|
| Lay out children in a row | flex |
| Lay out children in a column | flex flex-col |
| Center children both ways | flex items-center justify-center |
| Push children to both ends | justify-between |
| Wrap onto new lines | flex-wrap |
| Grow to fill the space left | flex-1 |
| Never shrink | shrink-0 |
| Align one child on its own | self-end |
| Reverse the order | flex-row-reverse |
| Move one child first | order-first |
| Initial size of a flex item | basis-1/3 |
| An inline flex container | inline-flex |
Grid
| What it does | Class |
|---|
| Three equal columns | grid grid-cols-3 |
One column on mobile, three from md | grid-cols-1 md:grid-cols-3 |
| Span two columns | col-span-2 |
| Span the full row | col-span-full |
| Start and end lines | col-start-2 col-end-4 |
| Custom column sizes | grid-cols-[200px_1fr] |
| Header, content and footer rows | grid-rows-[auto_1fr_auto] |
| As many card columns as fit | grid-cols-[repeat(auto-fill,minmax(12rem,1fr))] |
| Center items in their cells | place-items-center |
| Fill columns before rows | grid-flow-col |
| Inherit the parent's columns | grid-cols-subgrid |
Layout and position
| What it does | Class |
|---|
| Hide an element | hidden |
| Inline block | inline-block |
| Position children relative to this element | relative |
| Pin to the top right corner | absolute top-0 right-0 |
| Cover the positioned parent | absolute inset-0 |
| Fixed bar at the top of the window | fixed inset-x-0 top-0 |
| Stick to the top while scrolling | sticky top-0 |
| Stack above other elements | z-10 |
| Clip overflowing content | overflow-hidden |
| Scroll vertically when content overflows | overflow-y-auto |
| Crop an image to fill its box | object-cover |
| Centered page container | container mx-auto px-4 |
| Hide visually, keep for screen readers | sr-only |
| Split text into columns | columns-3 |
Borders, rings and outlines
| What it does | Class |
|---|
| A 1px border | border |
| Border width | border-2 |
| Border on one side | border-b |
| Dashed border | border-dashed |
| Rounded corners | rounded-lg |
| Circle or pill | rounded-full |
| Round the top corners only | rounded-t-xl |
| Lines between children | divide-y divide-gray-200 |
| Ring around the element | ring-2 ring-blue-500 |
| Gap between the element and its ring | ring-offset-2 |
| Ring inside the element | inset-ring inset-ring-gray-300 |
| Outline with an offset | outline-2 outline-offset-2 outline-sky-500 |
| Hide the outline, keep it in forced colors mode | outline-hidden |
Shadows and effects
| What it does | Class |
|---|
| Box shadow | shadow-md |
| Larger shadow | shadow-xl |
| Colored shadow | shadow-lg shadow-cyan-500/50 |
| Inner shadow | inset-shadow-sm |
| Text shadow | text-shadow-md |
| Drop shadow that follows the shape | drop-shadow-lg |
| Opacity | opacity-50 |
| Blur | blur-sm |
| Frosted glass | backdrop-blur-md bg-white/30 |
| Grayscale | grayscale |
| Blend with the background | mix-blend-multiply |
| Fade out the bottom half | mask-b-from-50% |
| Pointer cursor | cursor-pointer |
| Ignore clicks | pointer-events-none |
| Prevent text selection | select-none |
Transitions, transforms and animation
| What it does | Class |
|---|
| Animate color, opacity, shadow and transform changes | transition |
| Animate colors only | transition-colors |
| Duration and easing | duration-300 ease-in-out |
| Delay | delay-150 |
| Grow on hover | hover:scale-105 |
| Rotate | rotate-45 |
| Move up by half its height | -translate-y-1/2 |
| Center an absolutely positioned element | absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 |
| Transform origin | origin-top-left |
| Rotate in 3D (the parent sets a perspective) | rotate-x-45 perspective-distant |
| Spinner | animate-spin |
| Loading placeholder | animate-pulse |
| Animate only without reduced motion | motion-safe:animate-bounce |
| Turn off transitions for reduced motion | motion-reduce:transition-none |
| Fade in when the element first appears | transition-opacity starting:opacity-0 |
Responsive breakpoints
Breakpoints are mobile first: an unprefixed class applies at every width, and md: applies from that width up.
| What it does | Class |
|---|
| From 40rem (640px) up | sm:flex |
| From 48rem (768px) up | md:grid-cols-2 |
| From 64rem (1024px) up | lg:px-8 |
| From 80rem (1280px) up | xl:text-6xl |
| From 96rem (1536px) up | 2xl:max-w-7xl |
| Below a breakpoint only | max-md:hidden |
| Between two breakpoints | md:max-lg:flex |
| A one-off breakpoint | min-[900px]:grid-cols-4 |
Hide on mobile, show from md | hidden md:block |
Stack on mobile, row from md | flex flex-col md:flex-row |
| Landscape orientation | landscape:flex-row |
| When printing | print:hidden |
Hover, focus and other states
| What it does | Class |
|---|
| On hover | hover:bg-sky-700 |
| On keyboard focus | focus-visible:outline-2 |
| On focus | focus:border-blue-500 |
| While pressed | active:scale-95 |
| When disabled | disabled:opacity-50 |
| Invalid after the user has edited the field | user-invalid:border-red-500 |
| Checked checkbox or radio | checked:bg-blue-600 |
| First and last child | first:pt-0 last:pb-0 |
| Striped rows | odd:bg-white even:bg-gray-50 |
| Every child except the first | not-first:mt-4 |
| Style all direct children from the parent | *:rounded-md |
When the parent marked group is hovered | group-hover:underline |
| A named group | group-hover/item:visible |
When the sibling marked peer is invalid | peer-invalid:visible |
| When the element contains a checked input | has-checked:bg-indigo-50 |
| ARIA state | aria-expanded:rotate-180 |
| Data attribute | data-[state=open]:bg-gray-100 |
| Content before or after the element | after:content-['*'] after:text-red-500 |
Open details or dialog | open:bg-white |
| Mark a class important | bg-red-500! |
Dark mode
dark: follows the operating system's setting by default. To switch with a class, add the @custom-variant dark rule from the directives table below.
| What it does | Class |
|---|
| Background in dark mode | dark:bg-gray-900 |
| Text color in dark mode | dark:text-gray-100 |
| Hover in dark mode | dark:hover:bg-gray-800 |
| Native controls and scrollbars in dark colors | scheme-light dark:scheme-dark |
Container queries
Mark a parent with @container, then size its children by the container's width instead of the window's.
| What it does | Class |
|---|
| Make an element a container | @container |
| From a container width of 28rem up | @md:flex-row |
| Below a container width | @max-md:hidden |
| Between two container widths | @sm:@max-lg:grid-cols-2 |
| Name a container | @container/sidebar |
| Query the named container | @lg/sidebar:block |
| An exact container width | @min-[475px]:flex |
| Half the container's width | w-[50cqw] |
Arbitrary values and properties
| What it does | Class |
|---|
| Any value | top-[117px] |
| Spaces in a value become underscores | grid-cols-[1fr_500px_2fr] |
| A calculation | w-[calc(100%-2rem)] |
| A CSS variable | fill-(--brand-color) |
| A CSS variable with a type hint | text-(length:--title-size) |
| Any CSS property | [mask-type:luminance] |
| Style matching children | [&>p]:mt-2 |
| Style when the element has a class | [&.is-active]:font-bold |
Theme variables and directives
Tailwind CSS 4 is configured in CSS, not in tailwind.config.js.
| What it does | CSS |
|---|
| Load Tailwind CSS in your stylesheet | @import "tailwindcss"; |
Add a color (creates bg-brand, text-brand and the rest) | @theme { --color-brand: oklch(0.62 0.19 259); } |
Add a font (creates font-display) | @theme { --font-display: "Satoshi", sans-serif; } |
Add a breakpoint (creates 3xl:) | @theme { --breakpoint-3xl: 120rem; } |
| Change the spacing scale | @theme { --spacing: 0.3rem; } |
| Replace the whole color palette | @theme { --color-*: initial; --color-ink: #111827; --color-paper: #ffffff; } |
Add an animation (creates animate-wiggle) | @theme { --animate-wiggle: wiggle 1s ease-in-out infinite; @keyframes wiggle { 0%, 100% { rotate: -3deg; } 50% { rotate: 3deg; } } } |
Dark mode with a dark class | @custom-variant dark (&:where(.dark, .dark *)); |
| Dark mode with a data attribute | @custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *)); |
| A custom utility | @utility content-auto { content-visibility: auto; } |
| Use utilities inside your own CSS | .btn { @apply rounded-lg px-4 py-2 font-semibold; } |
| Use a variant inside your own CSS | .card { @variant dark { background: black; } } |
| Read a theme value in CSS | .note { color: var(--color-gray-500); } |
Prefix every class (tw:flex) | @import "tailwindcss" prefix(tw); |
| Scan a folder Tailwind would skip | @source "../node_modules/@acme/ui"; |
| Never scan a folder | @source not "./legacy"; |
| Always generate a class | @source inline("underline"); |
Setup and tools
| What it does | Command or code |
|---|
| Install for Vite | npm install tailwindcss @tailwindcss/vite |
Add the Vite plugin in vite.config.ts | plugins: [tailwindcss()] |
| Install for PostCSS | npm install tailwindcss @tailwindcss/postcss postcss |
The PostCSS config in postcss.config.mjs | export default { plugins: { "@tailwindcss/postcss": {} } }; |
| Install the command line tool | npm install tailwindcss @tailwindcss/cli |
| Build and watch with the command line tool | npx @tailwindcss/cli -i ./src/input.css -o ./src/output.css --watch |
| Build minified CSS for production | npx @tailwindcss/cli -i ./src/input.css -o ./dist/output.css --minify |
| Upgrade a Tailwind CSS 3 project | npx @tailwindcss/upgrade |
Renamed in Tailwind CSS 4
Some version 3 names still work but now mean a different size, such as shadow-sm; others are kept only for compatibility, and some, such as bg-opacity-50, are gone. npx @tailwindcss/upgrade makes these changes for you.
| Tailwind CSS 3 | Tailwind CSS 4 |
|---|
shadow-sm | shadow-xs |
shadow | shadow-sm |
rounded-sm | rounded-xs |
rounded | rounded-sm |
blur-sm | blur-xs |
drop-shadow-sm | drop-shadow-xs |
outline-none | outline-hidden |
ring | ring-3 |
bg-opacity-50 | bg-black/50 |
flex-shrink-0 | shrink-0 |
flex-grow | grow |
bg-gradient-to-r | bg-linear-to-r |
overflow-ellipsis | text-ellipsis |
decoration-clone | box-decoration-clone |
!font-bold | font-bold! |
bg-[--brand] | bg-(--brand) |
The Tailwind CSS classes you reach for most, in copy-paste tables: spacing, sizing, typography, color, flexbox, grid, borders and effects first, then breakpoints, hover and focus states, dark mode, container queries, and @theme with the other CSS directives.
Everything here is Tailwind CSS 4 syntax, and every Tailwind CSS 4 class and CSS snippet in the tables was built with the Tailwind CSS 4.1 compiler to check that it exists. Coming from version 3? The last table lists the renamed utilities. For the CSS properties underneath, see the CSS cheat sheet.