Sub topic 7
Resetting a namespace or the whole theme
This chapter assumes you know how @theme defines tokens and how namespaces such as --color-* and --font-* map to utilities. Extending the default theme adds tokens next to Tailwind's defaults. Resetting removes defaults, so your design system contains only what you define.
Resetting one namespace
Set a namespace wildcard to initial to remove every default variable in that namespace.
@import "tailwindcss";
@theme {
--color-*: initial;
--color-white: #fff;
--color-brand: #3f3cbb;
}Tailwind drops all default --color-* variables, so bg-red-500 and text-blue-600 no longer exist. Only white and brand generate color utilities, such as bg-brand and border-white.
Using a removed class causes no build error. Tailwind generates no CSS for it, and the element silently loses the style.
Overriding a single variable
You don't need a reset to change one default. Redefine the variable with the same name and your value replaces the default.
@theme {
--color-gray-500: oklch(0.55 0.02 260);
}All other grays keep their default values.
Resetting the whole theme
Use --*: initial to remove every default theme variable at once.
@import "tailwindcss";
@theme {
--*: initial;
--spacing: 4px;
--breakpoint-md: 48rem;
--font-body: "Inter", sans-serif;
--color-lagoon: oklch(0.72 0.11 221.19);
}Only the variables you list now exist. That has three consequences:
- Spacing utilities such as
p-4andgap-2need--spacing. Without it, the numeric scale has no base value. - Breakpoint variants such as
sm:andlg:disappear unless you define them. Here onlymd:works. - Fonts, shadows, radii, easing curves and the other namespaces are empty until you fill them.
Utilities that don't depend on theme variables, such as flex, hidden and grid, are unaffected.
Choosing a reset level
| Goal | Declaration | Result |
|---|---|---|
| Change one value | `--color-gray-500: ...` | One default replaced |
| Replace a palette | `--color-*: initial` | All default colors removed |
| Replace a design system | `--*: initial` | All default tokens removed |
Common errors
- Resetting colors and then using
bg-red-500in existing markup. Search your templates for removed names first. - Resetting everything and forgetting
--spacing, which breaksp-*,m-*,w-*and similar utilities. - Resetting everything and forgetting breakpoints, so responsive variants stop working.
Exercise
You write @theme { --color-*: initial; --color-brand: #3f3cbb; }. Your markup contains <button class="bg-brand text-white p-4">. Which of the three classes still produce CSS, and why?
Show answer
Only bg-brand and p-4 produce CSS. bg-brand works because --color-brand is defined after the reset. p-4 works because the reset only affects the --color-* namespace, so --spacing is untouched. text-white produces nothing because the default --color-white was removed. Add --color-white: #fff; to bring it back.