Variant, Property, Scale, Modifier
Anatomy of a Utility Class
Every utility follows a predictable shape — learn to read and predict class names instead of memorizing them.
What you'll learn
- Decode a stacked class like the dark hover example
- Understand the spacing and scale numbers
- Predict class names you have not memorized
Tailwind has hundreds of classes, but you do not memorize them — you learn the grammar. Once you can read the shape, you can predict names you have never seen.
Decoding One Class
Take md:hover:bg-blue-500/50 and split it on its parts:
md:— a responsive variant: apply at themdbreakpoint and up.hover:— a state variant: only while hovered.bg— the property: background color.blue-500— the scale value: hueblue, shade500./50— an opacity modifier: 50% alpha.
Read together: “from medium screens up, when hovered, set the background to blue-500 at 50% opacity.” The general shape is variant:variant:property-scale/modifier, and variants always read left to right.
The Spacing Scale
Numbers like the 4 in p-4 are not pixels — they are steps on a scale where each step is 0.25rem (4px at the default root size):
<div class="p-4">1rem of padding (4 × 0.25rem)</div>
<div class="mt-2">0.5rem top margin</div>
<div class="gap-8">2rem gap</div> This shared scale is why unrelated components still feel visually consistent.
Negative and Arbitrary Values
Two escape hatches round out the grammar:
<!-- Negative: prefix the dash -->
<div class="-mt-2">pulls up by 0.5rem</div>
<!-- Arbitrary: exact value in square brackets -->
<div class="top-[117px] grid-cols-[200px_1fr]">precise control</div> Arbitrary values let you escape the scale for the rare one-off without leaving the utility model — but reach for the scale first; that is what keeps designs consistent.
Responsive Prefixes →