Tailwind CSS Tutorial · Customizing Tailwind · Lesson 19 of 27

Theme Variables (@theme)

Customizing colours, fonts, spacing and breakpoints with CSS theme variables in @theme, Tailwind v4's CSS-first configuration.

Create a free account to save this page, take notes and track your progress. Sign in

CSS-first configuration

In v4 you customize Tailwind in CSS, with theme variables inside @theme. Each variable creates utilities:

@import "tailwindcss";

@theme {
  --color-brand-50: oklch(0.97 0.02 250);
  --color-brand-500: oklch(0.6 0.2 250);
  --color-brand-700: oklch(0.45 0.17 250);
  --font-display: "Inter", sans-serif;
  --breakpoint-3xl: 120rem;
  --radius-card: 1.25rem;
}
Namespace Creates
--color-* bg-brand-500, text-brand-700, border-brand-50…
--font-* font-display
--text-* font sizes (text-hero)
--breakpoint-* breakpoints (3xl:)
--radius-* rounded-card
--shadow-*, --spacing shadows, the spacing unit

The variables are also real CSS variables, so you can use them anywhere: var(--color-brand-500).

Custom colours and radiusTry it yourself
<style type="text/tailwindcss">
  @theme {
    --color-brand-50: oklch(0.97 0.02 250);
    --color-brand-500: oklch(0.6 0.2 250);
    --color-brand-700: oklch(0.45 0.17 250);
    --radius-card: 1.25rem;
  }
</style>
<div class="p-6">
  <div class="max-w-sm rounded-card bg-brand-50 p-6 ring-1 ring-brand-500/20">
    <p class="font-semibold text-brand-700">Your own design tokens</p>
    <p class="mt-1 text-sm text-gray-600">bg-brand-50, text-brand-700 and rounded-card come from @theme.</p>
    <button class="mt-4 rounded-lg bg-brand-500 px-4 py-2 text-white hover:bg-brand-700">Brand button</button>
  </div>
</div>

To replace a whole namespace (for example only your own colours), reset it first: --color-*: initial;. Projects upgrading from v3 can still load a JavaScript config with @config "./tailwind.config.js";.

Test yourself

In Tailwind v4, which @theme variable creates bg-brand-500?

  1. --color-brand-500
  2. --bg-brand-500
  3. --brand-500
  4. colors.brand.500
Show answer

Answer: --color-brand-500

Colour utilities come from the --color-* namespace.

Was this page helpful?