p-4 mt-8 text-blue-500 rounded-xl—incantations at first sight, but there are only three rules. Once they click, the memorisation load collapses and you can guess classes you’ve never seen.
Rule 1: a class name is “what” plus “how much”
Almost every class has this shape.
p-4
│ └── how much (the value)
└──── what (the property)The “what” part is an initial or abbreviation of a CSS property name.
| Prefix | CSS property | Example |
|---|---|---|
p- | padding | p-4 |
m- | margin | m-4 |
w- | width | w-full |
h- | height | h-screen |
bg- | background-color | bg-white |
text- | font-size or color | text-lg / text-red-500 |
border- | border | border-2 |
rounded- | border-radius | rounded-lg |
gap- | gap | gap-4 |
flex- | the flex family | flex-col |
To narrow it to one side, add one letter to the prefix. This part is regular, so you learn it once.
| Letter | Side | Example |
|---|---|---|
t | top | pt-4 mt-8 |
b | bottom | pb-4 mb-8 |
l / r | left / right | pl-4 pr-4 |
x | left and right | px-4 |
y | top and bottom | py-4 |
So px-4 py-2 is “1rem left and right, 0.5rem top and bottom”—the same as plain CSS’s padding: 0.5rem 1rem;. x and y come up constantly, so get those two into your hands early.
Rule 2: the numbers are steps, not pixels
This is the first thing that trips everyone. p-4 is not 4px.
The number says which step in the scale. By default one step is 0.25rem (4px at a 16px base), giving:
| Class | Actual value | In px |
|---|---|---|
p-1 | 0.25rem | 4px |
p-2 | 0.5rem | 8px |
p-3 | 0.75rem | 12px |
p-4 | 1rem | 16px |
p-6 | 1.5rem | 24px |
p-8 | 2rem | 32px |
p-12 | 3rem | 48px |
p-16 | 4rem | 64px |
The trick is “multiply by four to get px.” p-4 is 16px, p-6 is 24px, p-8 is 32px. You can do it in your head.
Values that aren’t numbers
The length family also has some useful non-numeric values.
| Class | Meaning |
|---|---|
w-full | width: 100% |
w-screen | The full screen width |
h-screen | The full screen height (100vh) |
w-fit | As wide as the content |
m-auto | margin: auto (for centring) |
p-px | 1px |
Rule 3: colours are “name plus shade”
Colours take the form name-shade.
bg-blue-500
│ │ └── shade (50–950)
│ └─────── colour name
└────────── what it's applied to (background)50 is the lightest, 950 the darkest.
| Shade | How it looks | Common use |
|---|---|---|
50 100 | Very light | Tinted backgrounds, a selected row |
200 300 | Light | Borders, dividers |
500 | The base | The brand colour itself |
600 700 | Dark | Text colour, button backgrounds |
800 900 | Very dark | Heading text |
The ones you’ll actually reach for most are 50–100 (backgrounds) and 600–700 (text). Use 500 for logos and accents; as a text colour it’s often too light to read comfortably.
<!-- light background, dark text: the readable classic -->
<p class="bg-blue-50 text-blue-800 p-4">Notice</p>The colour names are slate gray red orange amber yellow lime green emerald teal cyan sky blue indigo violet purple fuchsia pink rose. You don’t need them all—settling on three or four is enough.
Font sizes are names, not step numbers
Unlike the numeric scale, font sizes use clothing-size names.
| Class | Actual value | In px |
|---|---|---|
text-xs | 0.75rem | 12px |
text-sm | 0.875rem | 14px |
text-base | 1rem | 16px (default) |
text-lg | 1.125rem | 18px |
text-xl | 1.25rem | 20px |
text-2xl | 1.5rem | 24px |
text-3xl | 1.875rem | 30px |
text-4xl | 2.25rem | 36px |
base is the standard 16px; sm → xs go smaller, lg → xl → 2xl go larger. From 2xl up it counts in numbers, so big headings use text-3xl or text-4xl.
When the scale doesn’t have what you need
If you genuinely need a value that isn’t in the scale, square brackets take anything.
<div class="p-[13px] text-[#ff8a3d] w-[420px]">
arbitrary values
</div>Handy—but overusing it throws away the benefit of the scale (you’re back to drifting spacing). Save it for cases with a reason, like a specific value handed to you in a design file.
Test whether it stuck
Let’s check. What is this class list doing, in plain CSS?
<button class="px-6 py-3 bg-orange-500 text-white text-lg font-bold rounded-full">
Send
</button>The answer:
button {
padding: 0.75rem 1.5rem; /* py-3 px-6 → 12px 24px */
background-color: #f97316; /* bg-orange-500 */
color: #fff; /* text-white */
font-size: 1.125rem; /* text-lg */
font-weight: 700; /* font-bold */
border-radius: 9999px; /* rounded-full */
}You just read down the list. One class, one declaration, so it reads like translation.
Summary of this lesson
- A class name is “what-how much.” Narrow the side with
xytblr - Numbers are steps, not pixels.
p-4is 16px—multiply by four - Only having steps is what keeps spacing consistent across the whole site
- Colours are “name-shade.” 50 light, 950 dark; text at
600–700, backgrounds at50–100 text-does double duty—decided by what follows- Square brackets like
p-[13px]fill gaps, but overuse cancels the benefit
Next we use these rules to build Flexbox and Grid layouts, lined up one-to-one with the CSS you already know.