Sub topic 1
Where Utilities End: The Theme and Its Limits
Prerequisites
This chapter assumes you know the following:
- Basic HTML and CSS, including units, custom properties and selectors.
- Tailwind utility classes such as
p-4,text-lgandbg-blue-500. - Variant prefixes such as
hover:andmd:.
You don't need to have written any Tailwind configuration. This chapter explains what the theme is before it shows where the theme runs out.
What a utility class is
A utility class is a class name that maps to one small piece of CSS. p-4 sets padding, text-lg sets font size and line height, and bg-blue-500 sets a background color. Tailwind generates the CSS for these classes only when it finds them in your source files.
The class names are not hard-coded. Each one has two parts:
- A utility, such as
p,textorbg. It decides which CSS property is set. - A value, such as
4,lgorblue-500. It decides what that property is set to.
The value comes from the theme.
The theme
The theme is Tailwind's set of named design values. It holds your spacing scale, color palette, font sizes, breakpoints, shadows and more. When you write p-4, Tailwind looks up 4 in the spacing scale and produces the matching CSS.
The default spacing scale is based on a single step, so p-4 equals 1rem and p-8 equals 2rem. The colors use numbered shades, so blue-500 is one fixed blue.
This design has a clear benefit. Everyone on a project picks from the same short list of values, so spacing and color stay consistent without anyone having to enforce it.
| Utility | Theme lookup | Generated CSS |
|---|---|---|
| `p-4` | spacing step 4 | `padding: 1rem` |
| `text-lg` | font size `lg` | `font-size: 1.125rem` and a line height |
| `bg-blue-500` | color `blue-500` | a background color |
| `md:flex` | breakpoint `md` | `display: flex` inside a media query |
Where the theme runs out
A fixed scale cannot cover every design. Three kinds of gaps show up often.
- A value that is not in the scale. A designer specifies
top: 117px, a width of317px, or the brand color#bada55. No class name liketop-117exists, andw-[317px]is not on the default scale either. - A property with no utility. Tailwind ships utilities for most common CSS, but not for every property.
mask-typeis one example. You can write the CSS yourself, but nothing in the utility list sets it. - A condition with no variant. Tailwind provides variants such as
hover:,md:anddark:. A rule like "style only odd list items that are direct children" or "apply this only wheredisplay: gridis supported" has no built-in prefix.
Each gap has a matching escape hatch, and all three use square brackets. They are the subject of the rest of this tutorial.
| Gap | Escape hatch | Example |
|---|---|---|
| Value not in the theme | Arbitrary value | `w-[317px]` |
| Property with no utility | Arbitrary property | `[mask-type:luminance]` |
| Condition with no variant | Arbitrary variant | `[&>li:nth-child(odd)]:bg-gray-100` |
A first look at the three escape hatches
Here is a single element that touches the first escape hatch. The square brackets tell Tailwind to use the value inside them as written, instead of looking it up in the theme.
<div class="absolute top-[117px] left-[calc(50%-2rem)] w-[317px] bg-[#bada55]"></div>Tailwind reads top-[117px] as "use the top utility with the value 117px". It generates top: 117px and skips the theme. The same holds for the calc() expression, the width and the hex color.
The other two escape hatches look like this. Later chapters explain them in detail.
<div class="[mask-type:luminance] hover:[mask-type:alpha]"></div>
<ul class="[&>li:nth-child(odd)]:bg-gray-100 [@supports(display:grid)]:grid">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>The first line writes a CSS declaration directly, and it still works with hover:. The list wraps a selector or an at-rule in brackets, where & stands for the element itself.
Why the limits are intentional
The theme is a constraint, and the constraint is a feature. If every developer could type any pixel value, a project would drift toward dozens of slightly different spacings and colors. The brackets make a one-off visible. When you read w-[317px] in a template, you know that the value does not come from the design system.
That visibility matters later. A bracketed value that appears once is a fine exception. The same bracketed value repeated in ten places is a sign that the theme is missing an entry. The final chapter of this tutorial gives criteria for that decision.
Checking your understanding
Exercise
A design calls for margin-top: 23px, for mask-type: luminance, and for background color only on odd direct children of a list. For each requirement, name which escape hatch (arbitrary value, arbitrary property or arbitrary variant) you would use, and say why the theme cannot supply it.
Show answer
Margin of 23px needs an arbitrary value, such as mt-[23px], because a mt-* utility exists but 23px is not a step on the spacing scale. mask-type: luminance needs an arbitrary property, [mask-type:luminance], because no utility sets that property. The odd direct children need an arbitrary variant, such as [&>li:nth-child(odd)]:bg-gray-100, because no built-in variant describes that selector.
Exercise
In your own words, what are the two parts of the class bg-blue-500, and where does Tailwind find the value?
Show answer
bg is the utility, which decides that the background color property is set. blue-500 is the value, which Tailwind looks up in the theme's color palette.