Tailwind CSS Handbook v4.3

Your First Utilities

Learn to read a Tailwind class name, then build one component from a plain box to a responsive, interactive, dark-mode-aware card.

Every Tailwind class follows the same shape. Once you can read one, you can guess most of the rest.

Anatomy of a class#

TEXT
   md:hover:bg-indigo-600/80
   ─┬ ──┬── ─┬ ───┬──  ─┬─  ─┬
    │   │    │    │     │    └─ opacity modifier  → 80%
    │   │    │    │     └────── shade             → 600
    │   │    │    └──────────── colour            → indigo
    │   │    └───────────────── property          → background-color
    │   └────────────────────── state variant     → :hover
    └────────────────────────── breakpoint        → ≥ 48rem

Read it right to left: background colour indigo-600 at 80% opacity, on hover, from the medium breakpoint up.

PartMeaningDocs
bg-indigo-600The utility itselfColors
/80Opacity modifierColors
hover:State variantStates & Variants
md:Responsive variantResponsive Design
dark:Colour scheme variantDark Mode
[…]Arbitrary valueArbitrary Values

Variants stack left to right and can be combined freely: dark:md:hover:bg-indigo-500.

The scales you will use constantly#

Almost every numeric utility draws on the same spacing scale, where 1 = 0.25rem (4px by default).

ClassValueClassValue
p-10.25remp-61.5rem
p-20.5remp-82rem
p-30.75remp-102.5rem
p-41remp-123rem

The same numbers work for m-*, gap-*, w-*, h-*, top-* and more. Learn it once.

Build a card, step by step#

1. Basic#

Start with structure and no styling decisions beyond spacing and colour.

Loading preview…

Every class maps to one declaration:

  • max-w-sm → max-width: 24rem
  • rounded-xl → border-radius: 0.75rem
  • border border-gray-200 → a 1px border, explicitly coloured
  • p-6 → padding: 1.5rem
  • mt-2 → margin-top: 0.5rem

2. Responsive#

Design mobile-first: unprefixed classes are the small-screen baseline, prefixed classes take over at larger widths.

Loading preview…

The footer stacks on phones (flex-col) and becomes a row from 40rem up (sm:flex-row).

3. Interactive#

Add state with variants rather than extra CSS.

Loading preview…

4. Advanced#

Dark mode and group-driven state, still without leaving the markup.

Loading preview…

group on the parent lets children react to the parent's hover via group-hover:*. That is one of the highest-leverage variants in Tailwind — see States & Variants.

Utilities worth memorising first#

NeedReach for
Horizontal + vertical centringflex items-center justify-center
Even spacing between childrenflex gap-4 or grid gap-4
Page containermx-auto max-w-7xl px-6
Card surfacerounded-xl border p-6 shadow-sm
Muted body texttext-sm text-gray-600
Section headingtext-2xl font-semibold tracking-tight
Responsive column splitgrid gap-6 md:grid-cols-2

Common mistakes#

  • Using sm: for phones. sm: means 40rem and up. Unprefixed classes are the mobile baseline.
  • justify-center to centre vertically. justify-* follows the main axis. In a row, vertical centring is items-center.
  • Adding flex and expecting a gap. gap-* needs a flex or grid container; on a block element it does nothing.
  • Guessing class names. text-medium and font-lg do not exist. It is font-medium and text-lg.