Skip to main content
Tailwind CSS Mastery·Lesson 1 of 5

Utility-First Workflow

Tailwind CSS takes a radically different approach to styling. Instead of writing custom CSS classes like .card-title or .btn-primary, you compose designs directly in your markup using small, single-purpose utility classes.

Why Utility-First?

Traditional CSS encourages you to create abstractions early. You name things, group styles into classes, and hope the names stay relevant as designs evolve. In practice, this leads to bloated stylesheets full of dead or duplicated CSS.

With utility-first CSS:

  • No naming fatigue — you never agonize over class names.
  • No dead CSS — utilities are only included if used.
  • Local reasoning — you see exactly what an element looks like by reading its classes.
  • Safe changes — editing one element never accidentally breaks another.

Common Utility Classes

Here is a practical example that uses many of the most common utilities:

Ctrl+Enter
HTML
CSS
JS
Preview

Breaking this down:

UtilityWhat it does
max-w-mdSets max-width: 28rem
mx-autoCenters horizontally via margin-left/right: auto
rounded-lgApplies border-radius: 0.5rem
shadow-mdAdds a medium box shadow
p-6Adds padding: 1.5rem on all sides
text-xlSets font-size: 1.25rem
font-boldSets font-weight: 700
leading-relaxedSets line-height: 1.625

Responsive Prefixes

Tailwind uses a mobile-first breakpoint system. Unprefixed utilities apply at all screen sizes; prefixed utilities apply at that breakpoint and above.

Ctrl+Enter
HTML
CSS
JS
Preview

Default breakpoints:

PrefixMin-widthTypical device
sm:640pxLarge phones
md:768pxTablets
lg:1024pxLaptops
xl:1280pxDesktops
2xl:1536pxLarge screens

You can also use max-* variants for max-width breakpoints:

<p class="max-md:text-center md:text-left">
  Centered on small screens, left-aligned on medium and up.
</p>

State Variants

Tailwind provides variants for every interactive and structural state:

Ctrl+Enter
HTML
CSS
JS
Preview

Common state variants include hover:, focus:, active:, disabled:, first:, last:, odd:, even:, group-hover:, and peer-*:.

Combining Variants

Variants can be stacked. They read left to right — "on medium screens, when hovered":

<button class="bg-blue-600 md:hover:bg-blue-800 text-white px-4 py-2 rounded">
  Save
</button>

Arbitrary Values

When Tailwind's default scale does not have the exact value you need, use square brackets:

<div class="top-[117px] bg-[#1a1a2e] text-[clamp(1rem,2.5vw,2rem)]">
  Custom values
</div>

This keeps you in the utility workflow without dropping into a CSS file.