Tailwind CSS v4 Cheat Sheet: @theme, Variants, Arbitrary Values and v3 Changes
Checked against Tailwind CSS Tailwind CSS v4.3.5 (released 6 Nov 2026) on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers writing Tailwind CSS v4 or moving a project up from v3. It matches v4.3.5, the latest release on GitHub on 28 Nov 2026, and the tailwindcss.com docs. The Tailwind CLI is blocked in my shell here, so build output isn't shown and those rows are marked untested.
When to use what
In v4 your CSS file is the config. Put design tokens in @theme when they should produce utilities (--color-brand gives you bg-brand, text-brand and the rest), and in plain :root when they're just variables. Keep a tailwind.config.js only while migrating, loaded with @config.
For one-off values, an arbitrary value like top-[117px] is fine. If the same value shows up three times, it's a token and belongs in @theme. For a pattern that repeats across files, make a component in your framework before reaching for @apply. @apply is still useful for styling third-party markup you can't add classes to, and in Vue or Svelte style blocks you'll need @reference for it to see your theme.
Pick group when a child reacts to a parent's state, peer when an element reacts to an earlier sibling, and has-* when the parent reacts to what's inside it. Dark mode follows the OS by default; switch to a class or data attribute only if you offer a manual toggle.
Our CSS to Tailwind and Tailwind to CSS converters help when porting styles, and the Tailwind 4 setup post walks through a fresh install. For colour tokens, the Tailwind palette tool shows the default scale.
v4 needs Safari 16.4+, Chrome 111+ or Firefox 128+. Stay on v3.4 if you must support older browsers.
@import "tailwindcss";Replaces the three v3 @tailwind directives with a single import
npx @tailwindcss/upgradeOfficial v3 to v4 migration tool; needs Node.js 20+, so run it on a new branch
@tailwindcss/viteVite plugin, added as plugins: [tailwindcss()] in the Vite config
@tailwindcss/postcssPostCSS plugin; drop postcss-import and autoprefixer because v4 handles both
npx @tailwindcss/cli -i input.css -o output.cssBuilds with the standalone CLI package
@config "../../tailwind.config.js";Loads a legacy JS config, which v4 no longer finds on its own
@theme { --color-mint-500: oklch(0.72 0.11 178); }Adds bg-mint-500, text-mint-500, fill-mint-500 and a matching CSS variable
--breakpoint-3xl: 120rem;Inside @theme, creates a 3xl: responsive variant
--font-poppins: Poppins, sans-serif;Inside @theme, creates a font-poppins class
--color-*: initial;Removes every default colour so only your own remain
@theme inline { --font-sans: var(--font-inter); }Inlines the referenced value so variables resolve where the utility is used
--spacing: 0.25rem;The single base unit behind p-4, mt-2 and the other spacing utilities
md:grid-cols-4Applies from 48rem up; sm 40rem, lg 64rem, xl 80rem, 2xl 96rem
max-md:hiddenApplies below 48rem only
@container + @md:flex-rowContainer query: children change at a container width of 28rem or more
group + group-hover:text-whiteStyles a child when the parent marked group is hovered
group/item + group-hover/item:visibleNamed groups for nested hover targets
peer + peer-invalid:visibleShows an element when an earlier sibling is invalid; peers only work on previous siblings
has-checked:bg-indigo-50Styles a parent when it contains a checked input
data-[size=large]:p-8Styles based on a data attribute value
dark:bg-gray-900Applies under prefers-color-scheme: dark by default
[&.is-dragging]:cursor-grabbingArbitrary variant with your own selector; _ stands for a space
top-[117px]One-off value in square brackets; works with variants like lg:top-[344px]
bg-(--brand-color)Shorthand for bg-[var(--brand-color)]; v3's bg-[--brand-color] form changed
grid-cols-[1fr_500px_2fr]Underscores become spaces inside arbitrary values
text-(length:--my-var)Type hint so Tailwind knows the variable is a size, not a colour
[mask-type:luminance]Arbitrary property for CSS with no utility
bg-black/50Opacity modifier; replaces v3's removed bg-opacity-* utilities
Class detection rules are at https://tailwindcss.com/docs/detecting-classes-in-source-files.
@utility tab-4 { tab-size: 4; }Defines a custom utility that works with variants; replaces @layer utilities
@custom-variant dark (&:where(.dark, .dark *));Switches dark: to a .dark class for a manual toggle
@apply rounded-b-lg shadow-md;Inlines utilities into your own CSS rule
@reference "../../app.css";Lets a Vue, Svelte or CSS module block use @apply with your theme without duplicating CSS
@source "../node_modules/@acmecorp/ui-lib";Scans a path that automatic detection skips, like a package
@source inline("{hover:,}bg-red-{50,{100..900..100},950}");Safelists generated classes with brace expansion; replaces safelist
--alpha(var(--color-lime-300) / 50%)Compiles to a color-mix() with transparent
--spacing(4)Compiles to calc(var(--spacing) * 4)
shadow-sm -> shadow-xs, shadow -> shadow-smThe scale shifted down a step; same for rounded, blur and drop-shadow
outline-none -> outline-hiddenThe old behaviour moved; the new outline-none really sets outline-style: none
ring -> ring-3Bare ring is now 1px and uses currentColor instead of blue-500
flex-shrink-* -> shrink-*, flex-grow-* -> grow-*Old aliases were removed
!flex -> flex!The important modifier now goes at the end
first:*:pt-0 -> *:first:pt-0Stacked variants now apply left to right
tw:flex tw:hover:bg-red-600Prefixes now look like a variant and come first; set with prefix(tw) on the import
Worked example: Migrating a v3 card with a brand colour and manual dark mode
A v3 project had theme.extend.colors.brand in tailwind.config.js, darkMode: 'class' and markup like shadow ring bg-opacity-50. In v4 the whole config can move into the stylesheet.
@import "tailwindcss";
@theme {
--color-brand: oklch(0.623 0.188 259.8);
}
@custom-variant dark (&:where(.dark, .dark *));
<!-- v3 -->
<div class="bg-brand bg-opacity-50 shadow ring rounded">...</div>
<!-- v4 -->
<div class="bg-brand/50 shadow-sm ring-3 ring-blue-500 rounded-sm dark:bg-brand">...</div>
Each change has a reason from the upgrade guide. bg-opacity-50 is gone, so the alpha moves into the /50 modifier. The shadow and radius scales shifted, so v3's bare shadow and rounded become shadow-sm and rounded-sm to look the same. Bare ring is now 1px and currentColor, so ring-3 ring-blue-500 restores the old 3px blue ring. The @custom-variant line replaces darkMode: 'class'. I couldn't run the Tailwind CLI in this environment, so build the file yourself and diff the output; npx @tailwindcss/upgrade does most of these renames for you, and it's worth reviewing its diff line by line.
Common mistakes
Building class names from strings like
bg-${color}-600Tailwind scans files as plain text, so it never sees the full name. Map each option to a complete class string in an object.
Putting custom classes in
@layer utilitiesafter upgradingv4 doesn't treat those as utilities, so variants won't work on them. Define them with
@utilityinstead.Using
@applyin a Vue or Svelte style block and getting unknown utility errorsThose blocks are bundled separately. Add
@referencepointing at your main CSS file at the top of the block.Writing
bg-[--brand]for a CSS variablev4 uses parentheses for variables:
bg-(--brand). Square brackets now expect a literal value.Assuming
hover:styles show on phones after a tapv4 wraps hover in
@media (hover: hover). Add@custom-variant hover (&:hover);only if you really want the old behaviour.Borders turning dark after the upgrade
The default border colour is now
currentColor, not gray-200. Add an explicit colour likeborder-gray-200or restore the old default in@layer base.
Related cheat sheets
Sources
- https://tailwindcss.com/docs/upgrade-guide
- https://tailwindcss.com/docs/theme
- https://tailwindcss.com/docs/hover-focus-and-other-states
- https://tailwindcss.com/docs/dark-mode
- https://tailwindcss.com/docs/functions-and-directives
- https://tailwindcss.com/docs/adding-custom-styles
- https://tailwindcss.com/docs/detecting-classes-in-source-files
- https://github.com/tailwindlabs/tailwindcss/releases
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.