Sub topic 7
Resetting a namespace or the whole theme
This chapter assumes you know the @theme directive, that variable names carry a namespace prefix such as --color- or --font-, and that Tailwind v4 generates utilities from those variables. You should also know how to put @import "tailwindcss"; at the top of your CSS file.
The previous chapter showed how to extend the default theme by adding variables. Sometimes you want less, not more. A design system may allow eight brand colors and nothing else. Resetting lets you remove the defaults so that stray classes such as bg-red-500 stop working.
Three levels of override
Tailwind's default theme is a set of variables that @import "tailwindcss"; defines before your own CSS runs. A later @theme block can change that set at three levels.
| Goal | Declaration | Effect |
|---|---|---|
| Change one value | `--color-red-500: #c0392b;` | Replaces that variable. Other defaults stay. |
| Remove a namespace | `--color-*: initial;` | Removes every default variable in that namespace. |
| Remove everything | `--*: initial;` | Removes the whole default theme. |
The initial keyword is the CSS-wide keyword for "no value". Inside @theme, Tailwind reads initial as an instruction to delete the matching default variables. The CSS cascade does not process it.
Replacing one variable
Redefining a single variable overrides only that entry. The rest of the namespace is untouched.
@import "tailwindcss";
@theme {
--color-red-500: oklch(0.55 0.2 25);
--breakpoint-sm: 36rem;
}After this, bg-red-500 uses your red, bg-red-400 still uses the default, and the sm: variant starts at 36rem instead of the default.
Resetting a namespace
Use a wildcard name with initial to clear a namespace. The following example keeps only three colors.
@import "tailwindcss";
@theme {
--color-*: initial;
--color-white: #fff;
--color-black: #000;
--color-brand: #3f3cbb;
}The reset removes every default color, including white and black. If you still want bg-white, you have to define --color-white again, as above.
Now consider what happens to markup that used the old palette.
<div class="bg-brand text-white">
<button class="bg-blue-500 hover:bg-blue-700">Save</button>
</div>bg-brand and text-white work because their variables exist. bg-blue-500 and hover:bg-blue-700 generate no CSS, because --color-blue-500 and --color-blue-700 no longer exist. The button silently loses its background. Tailwind does not report an error for an unknown class.
Keep the reset before your definitions
Put the initial line first in the block, then add your own variables after it. The reset removes defaults that exist at that point. Writing your definitions first and the reset second makes the intent hard to read, and it invites a bug where you wipe out variables you just defined. Starting with the reset keeps the block easy to scan.
You can also reset in one @theme block and define in another. Both blocks sit after the default import, so the effect is the same.
Resetting other namespaces
Any namespace works the same way. These are the common ones.
| Reset | What disappears |
|---|---|
| `--font-*: initial;` | `font-sans`, `font-serif`, `font-mono` and any other font family utilities |
| `--breakpoint-*: initial;` | `sm:`, `md:`, `lg:`, `xl:`, `2xl:` variants |
| `--shadow-*: initial;` | `shadow-sm`, `shadow-md` and the rest |
| `--ease-*: initial;` | `ease-in`, `ease-out`, `ease-in-out` |
A common case is replacing the breakpoint scale with your own.
@import "tailwindcss";
@theme {
--breakpoint-*: initial;
--breakpoint-tablet: 40rem;
--breakpoint-laptop: 64rem;
--breakpoint-desktop: 80rem;
}Variants such as tablet:grid-cols-2 now exist, and md:grid-cols-2 does not. Order the breakpoints from small to large. Tailwind sorts the generated variants by value, so the smallest should be the one you intend as the base.
Resetting the whole theme
--*: initial; clears every default variable at once. You then build the theme from nothing.
@import "tailwindcss";
@theme {
--*: initial;
--spacing: 4px;
--font-body: Inter, sans-serif;
--color-white: #fff;
--color-ink: #1a1a2e;
--color-lagoon: oklch(0.72 0.11 221.19);
--breakpoint-md: 48rem;
}With this block, only the utilities backed by these variables exist. p-4 works because --spacing is defined and the utility computes calc(var(--spacing) * 4). If you left --spacing out, every spacing utility that depends on it, such as p-4, m-2 and gap-6, would stop generating.
Utilities that accept arbitrary values still work after a reset. bg-[#ff6600], w-[37rem] and p-[13px] do not depend on theme variables, so you can use them as an escape hatch while you build your own scale.
Resets and the default import
Everything above depends on the order Tailwind processes things. @import "tailwindcss"; brings in the defaults first. Your @theme block comes after it in the file, so its initial declarations see the defaults and remove them. If you move the @import below your @theme block, the defaults would arrive later and you would not get the behavior described here. Keep the import at the top.
Also remember that @theme must sit at the top level of the stylesheet. You cannot nest it inside a selector or a media query. That is true for resets too, so you cannot reset colors only for a dark mode this way. For runtime changes, use ordinary variables with @theme inline, which a later chapter covers.
Common mistakes
- Resetting and forgetting white and black. Many pages use
text-whiteorbg-black. Define both after clearing the color namespace. - Expecting an error for removed utilities. Missing utilities fail silently. Test the pages that matter, or search for the old class names before you merge.
- Resetting too broadly.
--*: initial;is the right tool for a closed design system. For a normal project that only needs a custom palette,--color-*: initial;is enough. - Misspelling the wildcard. The form is
--namespace-*: initial;, with a dash before the asterisk.--color*: initial;does not match the namespace. - Defining tokens in
:rootand expecting a reset to remove them. Resets only touch variables that belong to the theme. Variables you put in:rootare not part of it.
Choosing a level
- If you want a few tweaks, override single variables.
- If you want a controlled palette, font set, or breakpoint scale, reset that namespace and define your own values.
- If you are building a design system with strict limits, reset the whole theme and define each token you permit.
Exercise
Your stylesheet contains @theme { --color-*: initial; --color-brand: #3f3cbb; }. A component uses class="bg-brand text-white border-gray-200". Which of the three classes produce CSS, and what is the smallest change that makes all three work?
Show answer
Only bg-brand produces CSS. text-white fails because the reset removed --color-white, and border-gray-200 fails because it removed --color-gray-200. Add --color-white: #fff; and --color-gray-200: #e5e7eb; after the reset line. Tailwind then generates all three utilities.
Exercise
You want a project with only the breakpoints tablet at 40rem and desktop at 80rem, and no sm: or md: variants. Write the @theme block.
Show answer
@theme { --breakpoint-*: initial; --breakpoint-tablet: 40rem; --breakpoint-desktop: 80rem; }