Click any class group to expand the explanation and examples.
π Spacing (Padding & Margin)
p-{size} β Padding spacing
p-4 β padding: 1rem (16px) all sides px-4 β padding-left + right: 1rem py-2 β padding-top + bottom: 0.5rem pt-8 β padding-top: 2rem pr-0 β padding-right: 0 pb-6 β padding-bottom: 1.5rem pl-3 β padding-left: 0.75rem
x = horizontal, y = vertical, t/r/b/l = top/right/bottom/left.
m-{size} β Margin spacing
m-4 β margin: 1rem all sides mx-auto β margin-left + right: auto (center block) my-8 β margin-top + bottom: 2rem mt-4 β margin-top: 1rem -mt-4 β margin-top: -1rem (negative) mb-0 β margin-bottom: 0
mx-auto is the go-to for centering block elements.
gap-{size} β Gap spacing
gap-4 β gap: 1rem gap-x-4 β column-gap: 1rem gap-y-2 β row-gap: 0.5remUse
gap instead of adding margin to children β it's cleaner and doesn't affect the first/last child.
space-{x|y}-{size} β Space between spacing
space-x-4 β horizontal space between children space-y-2 β vertical space between childrenPrefer<div class=βspace-y-4β> <p>First</p> <!β no margin-top β> <p>Second</p> <!β margin-top: 1rem β> <p>Third</p> <!β margin-top: 1rem β> </div>
gap with flex/grid. Use space- for stacked block elements.
π Sizing
w-{size} / h-{size} β Width & Height sizing
w-64 β width: 16rem (256px) w-full β width: 100% w-screen β width: 100vw w-auto β width: auto w-1/2 β width: 50% w-1/3 β width: 33.333% w-fit β width: fit-contenth-16 β height: 4rem (64px) h-full β height: 100% h-screen β height: 100vh min-h-screen β min-height: 100vh
max-w-{size} β Max Width sizing
max-w-sm β 24rem (384px) max-w-md β 28rem (448px) max-w-lg β 32rem (512px) max-w-xl β 36rem (576px) max-w-2xl β 42rem (672px) max-w-4xl β 56rem (896px) max-w-7xl β 80rem (1280px) max-w-prose β 65ch (ideal for text) max-w-full β 100% max-w-none β none
max-w-7xl mx-auto is the classic container pattern.
π€ Typography
text-{size} β Font Size typography
text-xs β 0.75rem / 1rem text-sm β 0.875rem / 1.25rem text-base β 1rem / 1.5rem text-lg β 1.125rem / 1.75rem text-xl β 1.25rem / 1.75rem text-2xl β 1.5rem / 2rem text-3xl β 1.875rem / 2.25rem text-4xl β 2.25rem / 2.5rem text-5xl β 3rem / 1 text-6xl β 3.75rem / 1
font-{weight} β Font Weight typography
font-thin β 100 font-light β 300 font-normal β 400 font-medium β 500 font-semibold β 600 font-bold β 700 font-extrabold β 800 font-black β 900
leading-{size} / tracking-{size} β Line Height & Letter Spacing typography
leading-none β line-height: 1 leading-tight β line-height: 1.25 leading-normal β line-height: 1.5 leading-relaxed β line-height: 1.625 leading-loose β line-height: 2tracking-tighter β letter-spacing: -0.05em tracking-tight β letter-spacing: -0.025em tracking-normal β letter-spacing: 0 tracking-wide β letter-spacing: 0.025em tracking-wider β letter-spacing: 0.05em
text-{alignment} / truncate typography
text-left text-center text-right text-justify text-wrap text-nowraptruncate β overflow: hidden + text-overflow: ellipsis + white-space: nowrap line-clamp-3 β limit to 3 lines with ellipsis
truncate is perfect for card titles that might be too long.
π¨ Colors
text-{color}-{shade} / bg-{color}-{shade} colors
text-blue-500 β blue text bg-gray-100 β light gray background border-red-300 β light red borderColors: slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.text-white β white text text-black β black text bg-transparent β transparent background
With opacity
text-blue-500/75 β 75% opacity bg-black/50 β 50% opacity black overlay
π¦ Flexbox
flex / items-{align} / justify-{align} flexbox
flex β display: flex flex-row β direction: row (default) flex-col β direction: column flex-wrap β flex-wrap: wrapCenter anything:items-start β align-items: flex-start items-center β align-items: center items-end β align-items: flex-end items-stretch β align-items: stretch
justify-start β justify-content: flex-start justify-center β justify-content: center justify-end β justify-content: flex-end justify-between β justify-content: space-between justify-around β justify-content: space-around
flex items-center justify-center.
flex-1 / grow / shrink flexbox
flex-1 β flex: 1 1 0% (grow and shrink equally) flex-auto β flex: 1 1 auto flex-initial β flex: 0 1 auto flex-none β flex: none (don't grow or shrink)Common pattern β sidebar + content:grow β flex-grow: 1 grow-0 β flex-grow: 0 shrink β flex-shrink: 1 shrink-0 β flex-shrink: 0
<aside class=βw-64 shrink-0β> + <main class=βflex-1β>.
π² Grid
grid / grid-cols-{n} / grid-rows-{n} grid
grid β display: grid grid-cols-3 β 3 equal columns grid-cols-12 β 12-column grid grid-rows-3 β 3 equal rowscol-span-2 β span 2 columns col-span-full β span all columns col-start-2 β start at column 2
Responsive grid
<div class=βgrid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6β> <div>Card 1</div> <div>Card 2</div> <div>Card 3</div> </div>
πΌοΈ Borders & Shadows
border / rounded / shadow decoration
# Borders border β 1px solid border-2 β 2px solid border-t β top border only border-b-2 β bottom 2px border-gray-200 β border colorCard pattern:Border radius
rounded β 0.25rem rounded-md β 0.375rem rounded-lg β 0.5rem rounded-xl β 0.75rem rounded-2xl β 1rem rounded-full β 9999px (circle/pill)
Shadows
shadow-sm β small shadow shadow β default shadow shadow-md β medium shadow-lg β large shadow-xl β extra large shadow-none β no shadow
rounded-lg border border-gray-200 shadow-sm.
π± Responsive Design
sm: / md: / lg: / xl: / 2xl: β Breakpoints responsive
sm: β 640px and up md: β 768px and up lg: β 1024px and up xl: β 1280px and up 2xl: β 1536px and upAlways design mobile-first, then addExample: stack on mobile, side-by-side on desktop
<div class=βflex flex-col md:flex-row gap-4β> <div class=βw-full md:w-1/3β>Sidebar</div> <div class=βw-full md:w-2/3β>Content</div> </div>
Hide on mobile, show on desktop
<nav class=βhidden lg:blockβ>Desktop nav</nav> <button class=βlg:hiddenβ>β° Menu</button>
md: and lg: overrides.
π Dark Mode
dark: β Dark mode variant dark mode
<div class="bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100"> <p class="text-gray-600 dark:text-gray-400">Adapts to theme</p> <div class="border-gray-200 dark:border-gray-700">Card</div> </div>Enable in
tailwind.config.js: darkMode: 'class' (toggle via class on <html>) or 'media' (follows OS preference).
π±οΈ States (Hover, Focus, etc.)
hover: / focus: / active: β Interactive states states
hover:bg-blue-600 β background on hover focus:outline-none β remove outline on focus focus:ring-2 β add focus ring focus:ring-blue-500 β focus ring color active:scale-95 β shrink on click disabled:opacity-50 β dim when disabled group-hover:text-white β style child when parent hoveredButton example
<button class=βbg-blue-500 hover:bg-blue-600 active:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed text-white px-4 py-2 rounded-lg transitionβ> Click me </button>
π§© Common Patterns
Centered container pattern
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <!-- page content --> </div>
Card component pattern
<div class="rounded-lg border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-700 dark:bg-gray-800"> <h3 class="text-lg font-semibold">Title</h3> <p class="mt-2 text-gray-600 dark:text-gray-400">Description</p> </div>
Full-height layout pattern
<div class="flex min-h-screen flex-col"> <header class="shrink-0">Nav</header> <main class="flex-1">Content</main> <footer class="shrink-0">Footer</footer> </div>
Quick Reference Table
| Category | Most used classes |
|---|---|
| Spacing | p-4 px-6 m-2 mx-auto gap-4 |
| Sizing | w-full h-screen max-w-7xl min-h-screen |
| Typography | text-lg font-bold text-gray-600 leading-relaxed |
| Flexbox | flex items-center justify-between flex-col flex-1 |
| Grid | grid grid-cols-3 col-span-2 gap-6 |
| Borders | border rounded-lg border-gray-200 |
| Shadows | shadow-sm shadow-md shadow-lg |
| Responsive | sm: md: lg: xl: hidden md:block |
| Dark mode | dark:bg-gray-900 dark:text-white |
| States | hover:bg-blue-600 focus:ring-2 active:scale-95 |
| Display | hidden block inline-flex overflow-hidden |
| Position | relative absolute fixed sticky inset-0 |