TExcelTAD
Home › Tailwind CSS › Theme Variables

Theme Variables

Every value Tailwind uses — colours, fonts, breakpoints, radii, shadows — comes from theme variables. In v4 they are ordinary CSS custom properties declared with the @theme directive, and adding your own is as simple as writing one line of CSS.

Your first theme variable

css
@import "tailwindcss";

@theme {
  --color-mint-500: oklch(0.72 0.11 178);
}

Defining --color-mint-500 does two things:

  1. It creates utilities: bg-mint-500, text-mint-500, border-mint-500, fill-mint-500 … every colour utility.
  2. It emits a CSS variable --color-mint-500 on :root, so you can use var(--color-mint-500) in your own CSS or inline styles.
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
  <style type="text/tailwindcss">
    @theme {
      --color-mint-100: oklch(0.95 0.04 178);
      --color-mint-500: oklch(0.72 0.11 178);
      --color-mint-900: oklch(0.35 0.06 178);
    }
  </style>
</head>
<body class="p-6">
  <div class="rounded-xl border-2 border-mint-500 bg-mint-100 p-4 text-mint-900">
    <p class="font-bold">Custom mint palette</p>
    <p class="text-sm">bg-mint-100, border-mint-500, text-mint-900 — all generated from @theme.</p>
  </div>
  <div class="mt-3 h-6 rounded" style="background: var(--color-mint-500)"></div>
</body>
</html>

Theme namespaces

The prefix of the variable name decides which utilities it powers:

Namespace Example variable Utilities created
--color-* --color-brand: #e11d48 bg-brand, text-brand, border-brand …
--font-* --font-display: "Georgia", serif font-display
--text-* --text-huge: 5rem text-huge
--font-weight-* --font-weight-chunky: 850 font-chunky
--tracking-* / --leading-* --leading-cozy: 1.4 leading-cozy
--breakpoint-* --breakpoint-3xl: 120rem 3xl: variant
--container-* --container-narrow: 30rem max-w-narrow, @narrow:
--spacing --spacing: 0.3rem the base for p-*, m-*, w-* …
--radius-* --radius-blob: 2rem rounded-blob
--shadow-* --shadow-hard: 4px 4px 0 black shadow-hard
--animate-* --animate-wiggle: … animate-wiggle
--ease-* --ease-snappy: cubic-bezier(.2,0,0,1) ease-snappy
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
  <style type="text/tailwindcss">
    @theme {
      --font-display: "Georgia", "Times New Roman", serif;
      --text-huge: 3.5rem;
      --radius-blob: 2rem 0.5rem 2rem 0.5rem;
      --shadow-hard: 6px 6px 0 var(--color-gray-900);
      --color-banana: #ffe135;
    }
  </style>
</head>
<body class="p-6">
  <div class="inline-block rounded-blob border-2 border-gray-900 bg-banana px-6 py-4 shadow-hard">
    <h1 class="font-display text-huge leading-none font-bold">Retro</h1>
    <p class="text-sm">font-display · text-huge · rounded-blob · shadow-hard</p>
  </div>
</body>
</html>

Extending vs replacing

Variables you add inside @theme extend the default theme. To remove defaults, set a namespace to initial:

css
@theme {
  --color-*: initial;          /* drop the whole default palette */
  --color-ink: #1b1b1f;
  --color-paper: #fdfcf7;
  --color-accent: #ff5a1f;
}

Now only ink, paper and accent colours exist (plus keywords like transparent and current). Use --*: initial; to start from a completely empty theme.

Overriding a default value

Redefine an existing variable to change it everywhere. Changing --spacing rescales every padding, margin, width and gap at once:

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
  <style type="text/tailwindcss">
    @theme {
      --spacing: 0.35rem;            /* default is 0.25rem */
      --color-sky-500: #ff2d95;      /* yes, you can repaint a built-in colour */
      --breakpoint-sm: 30rem;
    }
  </style>
</head>
<body class="p-4">
  <div class="rounded-lg bg-sky-500 p-4 text-white">p-4 is now 1.4rem, and "sky-500" is pink!</div>
  <div class="mt-4 w-40 rounded-lg bg-gray-200 p-2 text-sm">w-40 = 14rem now</div>
</body>
</html>

Note: Overriding built-in names like sky-500 is legal but confusing for teammates. Prefer meaningful new names such as --color-brand-500.

@theme vs :root

Why not just write :root { --color-brand: … }? A plain CSS variable doesn't create utilities. Use @theme for design tokens that should become classes, and :root for variables you only read with var().

@theme inline { … } is a variant used when a theme value refers to another variable: it inlines the reference into the generated utilities so it resolves where the class is used.

css
@theme inline {
  --font-sans: var(--font-inter);
}

Coming from tailwind.config.js

v3 config v4 CSS
theme.extend.colors.brand = '#e11d48' --color-brand: #e11d48;
theme.extend.fontFamily.display = [...] --font-display: …;
theme.screens.3xl = '1920px' --breakpoint-3xl: 120rem;
theme.colors = { … } (replace) --color-*: initial; then your colours

A legacy JavaScript config can still be loaded with @config "./tailwind.config.js"; while you migrate.

Test yourself

Which variable creates a font-display utility?

  1. --display-font
  2. --font-display
  3. --family-display
  4. --text-display

How do you remove the entire default colour palette before adding your own?

  1. --color-*: initial; inside @theme
  2. colors: false in package.json
  3. @theme reset colors;
  4. Delete the palette from node_modules

What is the difference between declaring a variable in @theme and in :root?

  1. There is none
  2. @theme variables also generate utility classes
  3. :root variables are faster
  4. @theme variables can't be read with var()