πŸ“‹ Cheat Sheets

Tailwind CSS Cheat Sheet β€” Most Used Classes Quick Reference


Click any class group to expand the explanation and examples.

πŸ“ Spacing (Padding & Margin)

p-{size} β€” Padding spacing
Add padding to an element. Scale: 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 96. Each unit = 0.25rem (4px).
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
Add margin to an element. Same scale as padding.
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
Set gap between flex/grid children.
gap-4      β†’ gap: 1rem
gap-x-4    β†’ column-gap: 1rem
gap-y-2    β†’ row-gap: 0.5rem
Use 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
Add space between child elements (uses margin on children).
space-x-4  β†’ horizontal space between children
space-y-2  β†’ vertical space between children

<div class=β€œspace-y-4”> <p>First</p> <!β€” no margin-top β€”> <p>Second</p> <!β€” margin-top: 1rem β€”> <p>Third</p> <!β€” margin-top: 1rem β€”> </div>

Prefer gap with flex/grid. Use space- for stacked block elements.

πŸ“ Sizing

w-{size} / h-{size} β€” Width & Height sizing
Set width and height. Accepts the spacing scale plus special values.
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-content

h-16 β†’ height: 4rem (64px) h-full β†’ height: 100% h-screen β†’ height: 100vh min-h-screen β†’ min-height: 100vh

max-w-{size} β€” Max Width sizing
Constrain the maximum width. Essential for readable content.
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
Set font size with matching line height.
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
Set font weight.
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
Fine-tune text spacing.
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: 2

tracking-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 alignment and overflow handling.
text-left     text-center    text-right
text-justify  text-wrap      text-nowrap

truncate β†’ 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
Apply colors to text, backgrounds, and borders. Shades: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950.
text-blue-500     β†’ blue text
bg-gray-100       β†’ light gray background
border-red-300    β†’ light red border

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

Colors: slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.

πŸ“¦ Flexbox

flex / items-{align} / justify-{align} flexbox
Flexbox layout utilities.
flex             β†’ display: flex
flex-row         β†’ direction: row (default)
flex-col         β†’ direction: column
flex-wrap        β†’ flex-wrap: wrap

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

Center anything: flex items-center justify-center.

flex-1 / grow / shrink flexbox
Control how flex children grow and shrink.
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)

grow β†’ flex-grow: 1 grow-0 β†’ flex-grow: 0 shrink β†’ flex-shrink: 1 shrink-0 β†’ flex-shrink: 0

Common pattern β€” sidebar + content: <aside class=β€œw-64 shrink-0”> + <main class=β€œflex-1”>.

πŸ”² Grid

grid / grid-cols-{n} / grid-rows-{n} grid
CSS Grid layout utilities.
grid                β†’ display: grid
grid-cols-3         β†’ 3 equal columns
grid-cols-12        β†’ 12-column grid
grid-rows-3         β†’ 3 equal rows

col-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 radius, and box shadows.
# Borders
border          β†’ 1px solid
border-2        β†’ 2px solid
border-t        β†’ top border only
border-b-2      β†’ bottom 2px
border-gray-200 β†’ border color

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

Card pattern: rounded-lg border border-gray-200 shadow-sm.

πŸ“± Responsive Design

sm: / md: / lg: / xl: / 2xl: β€” Breakpoints responsive
Tailwind is mobile-first. Unprefixed classes apply to all sizes, prefixed classes apply at that breakpoint and up.
sm:   β†’ 640px and up
md:   β†’ 768px and up
lg:   β†’ 1024px and up
xl:   β†’ 1280px and up
2xl:  β†’ 1536px and up

Example: 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>

Always design mobile-first, then add md: and lg: overrides.

πŸŒ™ Dark Mode

dark: β€” Dark mode variant dark mode
Apply styles only in 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
Apply styles on user interaction.
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 hovered

Button 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
The most common page layout wrapper.
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
  <!-- page content -->
</div>
Card component pattern
A reusable card 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
Sticky header + scrollable content + footer.
<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

CategoryMost used classes
Spacingp-4 px-6 m-2 mx-auto gap-4
Sizingw-full h-screen max-w-7xl min-h-screen
Typographytext-lg font-bold text-gray-600 leading-relaxed
Flexboxflex items-center justify-between flex-col flex-1
Gridgrid grid-cols-3 col-span-2 gap-6
Bordersborder rounded-lg border-gray-200
Shadowsshadow-sm shadow-md shadow-lg
Responsivesm: md: lg: xl: hidden md:block
Dark modedark:bg-gray-900 dark:text-white
Stateshover:bg-blue-600 focus:ring-2 active:scale-95
Displayhidden block inline-flex overflow-hidden
Positionrelative absolute fixed sticky inset-0