How to read a Tailwind class name, piece by piece
Learn how to split a Tailwind class into its prefix, name, and shade, then chain a few classes on one element without guessing.

You open some HTML and see class="md:hover:bg-blue-600 px-4 py-2 rounded-lg". How do you read that?
Short answer: most Tailwind classes follow one pattern: optional conditions, then the property, then the value, separated by dashes and colons. md:hover:bg-blue-600 reads as "on medium screens and up, on hover, set the background to blue, shade 600".
Once you can split a class into those pieces, a long class attribute stops looking like noise. This post walks through each piece with examples, then shows how to read and write a full set of classes on one element. If you are still deciding whether to learn Tailwind at all, read Tailwind CSS vs CSS for beginners first.
The pattern
Almost every class you meet fits this shape:
variant:variant:property-value- Variants are optional. They end in a colon and say when the style applies: on hover, on a wider screen, in dark mode.
- Property is the short name for what you are changing:
bgfor background,pfor padding,textfor text. - Value says how much or which one: a size like
4, a color likeblue-600, or a word likelg.
Naming Anatomy (opens in a new tab) teaches this in the course.
Piece 1: the property
The first part is usually an abbreviation of a CSS property. A few to learn first:
| Prefix | Means | CSS it sets |
|---|---|---|
bg | background | background-color |
text | text | color or font-size, depending on the value |
p, px, py, pt | padding | all sides, left and right, top and bottom, top |
m, mx, my, mt | margin | same pattern as padding |
w, h | width, height | width, height |
rounded | rounded corners | border-radius |
border | border | border-width or border-color |
font | font | font-weight or font-family |
The direction letters are worth memorising once: x is left and right, y is top and bottom, and t, r, b, l are top, right, bottom and left. So pt-2 is padding on the top, and mx-auto is auto margin on the left and right, which centres a block.
Piece 2: the value
After the dash comes the value. It is one of three kinds.
A number from the spacing scale. For padding, margin, width, height and gap, the number is a step on a scale, not pixels. Each step is a quarter of a rem, so with default settings:
p-1 → 0.25rem (4px)
p-2 → 0.5rem (8px)
p-4 → 1rem (16px)
p-8 → 2rem (32px)So p-4 is 16 pixels of padding, not 4.
A color and a shade. Colors are a family name and a number from 50 (lightest) to 950 (darkest):
bg-blue-100 → very light blue
bg-blue-500 → the middle blue
bg-blue-900 → very dark blueColor Families (opens in a new tab) and Color Shades (opens in a new tab) cover the full palette.
A size word. Some properties use named sizes instead: sm, md, lg, xl, 2xl. You will see them on text, rounded and shadow. rounded-lg is a larger radius than rounded-sm.
Why text means two things
text-lg and text-blue-600 both start with text, but they set different CSS. Tailwind decides from the value:
- A size word like
text-lgsetsfont-size. - A color like
text-blue-600setscolor. - An alignment like
text-centersetstext-align.
So when you see text-, read the value before deciding what it does. Text Color (opens in a new tab) and Font Size (opens in a new tab) show each one.
Piece 3: variants before the colon
Anything before a colon is a condition. The style after it only applies when the condition is true.
<button class="bg-blue-500 hover:bg-blue-600">Save</button>That reads as "blue 500 normally, blue 600 on hover". The variants you will use most:
| Variant | Applies when |
|---|---|
hover: | The mouse is over the element |
focus: | The element has keyboard focus |
sm:, md:, lg: | The screen is at least that wide |
dark: | Dark mode is on |
disabled: | The element is disabled |
You can stack them. md:hover:bg-blue-600 means "on medium screens and wider, when hovered".
Screen size variants mean this width and up, not only this width. md:text-lg applies from medium screens upward. Write the mobile style first with no prefix, then override it for bigger screens.
Small extras you will see
- A slash for opacity.
bg-black/50is black at 50% opacity. - A leading minus for negative values.
-mt-2is a negative top margin. - Square brackets for one-off values.
w-[300px]sets an exact width that isn't on the scale. Use these sparingly. If you need the same value often, it probably belongs in your theme.
Reading a full element
Here is a card:
<div class="max-w-sm mx-auto p-6 bg-white rounded-xl shadow-md">
<h2 class="text-xl font-semibold text-gray-900">Learn Tailwind</h2>
<p class="mt-2 text-gray-600">Small classes, read one at a time.</p>
</div>Read the div left to right:
max-w-sm: maximum width, small.mx-auto: auto margin left and right, so it is centred.p-6: padding on all sides, step 6, which is 1.5rem.bg-white: white background.rounded-xl: extra-large rounded corners.shadow-md: medium shadow.
Then the heading: font size xl, weight semibold, color gray 900. Then the paragraph: top margin step 2, color gray 600. Each class does one thing. Chaining Classes Together (opens in a new tab) has you build this kind of chain yourself.
Writing your own: translate one property at a time
When you know the CSS you want, translate it piece by piece:
| You want | Property | Value | Class |
|---|---|---|---|
| 16px padding | p | step 4 | p-4 |
| Light gray background | bg | gray, shade 100 | bg-gray-100 |
| Bold text | font | bold | font-bold |
| Darker on hover | hover: + bg | gray, shade 200 | hover:bg-gray-200 |
The order of classes in the attribute doesn't change the result, so put them in whatever order you find easiest to read. Many people go layout, then spacing, then color, then states.
Common mistakes
- Reading numbers as pixels.
p-4is 16px, not 4px. The number is a step on the scale. - Expecting
md:to mean medium only. It means medium and up. Style for mobile first. - Mixing up the two
textclasses.text-lgis size,text-gray-600is color. You often need both. - Building class names from strings. Tailwind only generates classes it can find written out in your files, so
"bg-" + colorwon't work. Write the full class name. - Reaching for square brackets too early. If
w-[317px]appears everywhere, a scale value is usually close enough.
Quick recap
- Read a class as variants, then property, then value:
hover:bg-blue-600. - Spacing numbers are steps on a scale. Each step is a quarter rem, so
4is 16px. - Colors are a family plus a shade from 50 to 950.
text-is size, color or alignment, depending on the value.- Screen variants like
md:apply from that width upward.
Frequently asked questions
What does the number in a Tailwind class mean?
For spacing and sizing classes, it is a step on the spacing scale. With default settings each step is 0.25rem, so p-4 is 1rem, which is 16px. For colors, the number is the shade, from 50 for lightest to 950 for darkest.
What does md: mean in Tailwind?
It is a screen size variant. md: applies the style when the screen is at least the medium breakpoint wide, and on every size above it.
Does the order of Tailwind classes matter?
No. The order you write classes in the attribute doesn't decide which one wins. If two classes set the same property, remove one rather than relying on order.
How do I remember all the Tailwind class names?
You don't need to. Learn the pattern and a handful of prefixes, then look up the rest when you need them. After a few small projects, the common ones stick.
Do I need to know CSS to read Tailwind?
It helps a lot. Every Tailwind class maps to a CSS property, so knowing what padding, margin and flexbox do makes the class names obvious.
Practice
The matching exercises are in Tailwind CSS Basics. Start with Utility Classes (opens in a new tab), learn the naming pattern in Naming Anatomy (opens in a new tab), then combine classes in Chaining Classes Together (opens in a new tab) and Utility Card (opens in a new tab). Everything runs in your browser, so there is nothing to install.
Keep going
Tailwind CSS Basics (opens in a new tab) takes you from your first utility class to colors, spacing and flexbox layouts. If the CSS behind the classes still feels new, CSS Basics (opens in a new tab) is the best first step.







