Skip to content

Menu

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

From the docs, not run by us
npx @tailwindcss/upgrade

Official v3 to v4 migration tool; needs Node.js 20+, so run it on a new branch

From the docs, not run by us
@tailwindcss/vite

Vite plugin, added as plugins: [tailwindcss()] in the Vite config

From the docs, not run by us
@tailwindcss/postcss

PostCSS plugin; drop postcss-import and autoprefixer because v4 handles both

From the docs, not run by us
npx @tailwindcss/cli -i input.css -o output.css

Builds with the standalone CLI package

From the docs, not run by us
@config "../../tailwind.config.js";

Loads a legacy JS config, which v4 no longer finds on its own

From the docs, not run by us
@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

Try it: Tailwind Palette GeneratorFrom the docs, not run by us
--breakpoint-3xl: 120rem;

Inside @theme, creates a 3xl: responsive variant

From the docs, not run by us
--font-poppins: Poppins, sans-serif;

Inside @theme, creates a font-poppins class

From the docs, not run by us
--color-*: initial;

Removes every default colour so only your own remain

From the docs, not run by us
@theme inline { --font-sans: var(--font-inter); }

Inlines the referenced value so variables resolve where the utility is used

From the docs, not run by us
--spacing: 0.25rem;

The single base unit behind p-4, mt-2 and the other spacing utilities

From the docs, not run by us
md:grid-cols-4

Applies from 48rem up; sm 40rem, lg 64rem, xl 80rem, 2xl 96rem

From the docs, not run by us
max-md:hidden

Applies below 48rem only

From the docs, not run by us
@container + @md:flex-row

Container query: children change at a container width of 28rem or more

From the docs, not run by us
group + group-hover:text-white

Styles a child when the parent marked group is hovered

From the docs, not run by us
group/item + group-hover/item:visible

Named groups for nested hover targets

From the docs, not run by us
peer + peer-invalid:visible

Shows an element when an earlier sibling is invalid; peers only work on previous siblings

From the docs, not run by us
has-checked:bg-indigo-50

Styles a parent when it contains a checked input

From the docs, not run by us
data-[size=large]:p-8

Styles based on a data attribute value

From the docs, not run by us
dark:bg-gray-900

Applies under prefers-color-scheme: dark by default

From the docs, not run by us
[&.is-dragging]:cursor-grabbing

Arbitrary variant with your own selector; _ stands for a space

From the docs, not run by us
top-[117px]

One-off value in square brackets; works with variants like lg:top-[344px]

Try it: css-to-tailwindFrom the docs, not run by us
bg-(--brand-color)

Shorthand for bg-[var(--brand-color)]; v3's bg-[--brand-color] form changed

Try it: tailwind-to-cssFrom the docs, not run by us
grid-cols-[1fr_500px_2fr]

Underscores become spaces inside arbitrary values

From the docs, not run by us
text-(length:--my-var)

Type hint so Tailwind knows the variable is a size, not a colour

From the docs, not run by us
[mask-type:luminance]

Arbitrary property for CSS with no utility

From the docs, not run by us
bg-black/50

Opacity modifier; replaces v3's removed bg-opacity-* utilities

From the docs, not run by us

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

From the docs, not run by us
@custom-variant dark (&:where(.dark, .dark *));

Switches dark: to a .dark class for a manual toggle

From the docs, not run by us
@apply rounded-b-lg shadow-md;

Inlines utilities into your own CSS rule

From the docs, not run by us
@reference "../../app.css";

Lets a Vue, Svelte or CSS module block use @apply with your theme without duplicating CSS

From the docs, not run by us
@source "../node_modules/@acmecorp/ui-lib";

Scans a path that automatic detection skips, like a package

From the docs, not run by us
@source inline("{hover:,}bg-red-{50,{100..900..100},950}");

Safelists generated classes with brace expansion; replaces safelist

From the docs, not run by us
--alpha(var(--color-lime-300) / 50%)

Compiles to a color-mix() with transparent

From the docs, not run by us
--spacing(4)

Compiles to calc(var(--spacing) * 4)

From the docs, not run by us
shadow-sm -> shadow-xs, shadow -> shadow-sm

The scale shifted down a step; same for rounded, blur and drop-shadow

From the docs, not run by us
outline-none -> outline-hidden

The old behaviour moved; the new outline-none really sets outline-style: none

From the docs, not run by us
ring -> ring-3

Bare ring is now 1px and uses currentColor instead of blue-500

From the docs, not run by us
flex-shrink-* -> shrink-*, flex-grow-* -> grow-*

Old aliases were removed

From the docs, not run by us
!flex -> flex!

The important modifier now goes at the end

From the docs, not run by us
first:*:pt-0 -> *:first:pt-0

Stacked variants now apply left to right

From the docs, not run by us
tw:flex tw:hover:bg-red-600

Prefixes now look like a variant and come first; set with prefix(tw) on the import

From the docs, not run by us

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}-600

    Tailwind 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 utilities after upgrading

    v4 doesn't treat those as utilities, so variants won't work on them. Define them with @utility instead.

  • Using @apply in a Vue or Svelte style block and getting unknown utility errors

    Those blocks are bundled separately. Add @reference pointing at your main CSS file at the top of the block.

  • Writing bg-[--brand] for a CSS variable

    v4 uses parentheses for variables: bg-(--brand). Square brackets now expect a literal value.

  • Assuming hover: styles show on phones after a tap

    v4 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 like border-gray-200 or restore the old default in @layer base.