Sub topic 4
Namespaces: how a variable name picks its utilities
This chapter assumes you know CSS custom properties, can write Tailwind utility classes, and have @import "tailwindcss"; working in a CSS file. It also assumes you have seen a basic @theme block.
The prefix is the instruction
Tailwind does not guess what a theme variable is for. It reads the namespace, which is the prefix of the variable name, and uses it to decide which utilities and variants to generate. The rest of the name becomes the suffix of the class.
@import "tailwindcss";
@theme {
--color-brand: #3f3cbb;
--text-huge: 4rem;
--radius-pill: 9999px;
}--color-brandproducesbg-brand,text-brand,border-brandand every other color utility.--text-hugeproducestext-huge, which sets a font size.--radius-pillproducesrounded-pill.
Common namespaces
| Namespace | Generates | Example variable | Example class |
|---|---|---|---|
| `--color-*` | Color utilities such as `bg-*`, `text-*`, `border-*`, `fill-*` | `--color-brand` | `bg-brand` |
| `--font-*` | Font family utilities | `--font-display` | `font-display` |
| `--text-*` | Font size utilities | `--text-huge` | `text-huge` |
| `--font-weight-*` | Font weight utilities | `--font-weight-black` | `font-black` |
| `--breakpoint-*` | Responsive variants | `--breakpoint-3xl` | `3xl:grid-cols-6` |
| `--container-*` | Container query variants and container sizes | `--container-card` | `@card:flex` |
| `--spacing-*` | Padding, margin, gap, width and height utilities | `--spacing-gutter` | `px-gutter` |
| `--radius-*` | Border radius utilities | `--radius-pill` | `rounded-pill` |
| `--shadow-*` | Box shadow utilities | `--shadow-soft` | `shadow-soft` |
| `--ease-*` | Transition timing utilities | `--ease-fluid` | `ease-fluid` |
| `--animate-*` | Animation utilities | `--animate-fade-in` | `animate-fade-in` |
Two rows need attention. A namespace can produce variants as well as utilities, as --breakpoint-* does. And one namespace can feed many utilities: a single --color-* variable works with every property that takes a color.
How the name resolves
The diagram shows how Tailwind reads one variable name.
Tailwind matches the longest known namespace. That is why --font-weight-black is a weight and not a font family named weight-black.
Errors that look like bugs
A variable with no known namespace is still a valid CSS variable, but it creates no utility.
@theme {
--avocado-500: oklch(0.84 0.18 117.33);
--color-avocado-500: oklch(0.84 0.18 117.33);
}Here bg-avocado-500 works only because of the second line. The first line is emitted as a variable and does nothing else.
Another frequent mix-up is text-*. The class text-huge reads --text-huge and sets size. The class text-brand reads --color-brand and sets color. The class name alone does not say which namespace is used, so check the value type.
Exercise
You add --shadow-glow: 0 0 20px rgb(0 0 0 / 0.3); and --glow-color: #ff0; inside @theme. Which one creates a utility class, what is the class, and why does the other not?
Show answer
--shadow-glow creates shadow-glow, because the --shadow-* namespace maps to box shadow utilities. --glow-color has no recognized namespace (it would need to be --color-glow), so Tailwind generates no class for it.