Code Reference

Spacing & Sizing

Tailwind · Reference cheat sheet

Spacing & Sizing

Tailwind · Reference cheat sheet


📋 Overview

Spacing and sizing scales are theme tokens (usually 4px units). Prefer the scale for consistency; use arbitrary values when the design demands it.

🔧 Core concepts

PrefixCSS
p-* / px-* / py-* / pt-*padding
m-* / negative -m-*margin
gap-*flex/grid gap
space-x-* / space-y-*child margins
w-* / h-*width / height
min-* / max-*min/max size
size-*width + height together
Scale tipExample
4 → 1remp-4
0.5 → 0.125remgap-0.5
full100%
screen100vh (h-screen)

💡 Examples

Padding + gap:

<section class="p-6">
  <div class="flex gap-3">
    <button class="px-3 py-2">A</button>
    <button class="px-3 py-2">B</button>
  </div>
</section>

Width constraints:

<div class="mx-auto w-full max-w-3xl px-4">Readable measure</div>

Square icon button:

<button class="size-10 rounded-full">♪</button>

⚠️ Pitfalls

  • space-y-* + gap-* together can double spacing.
  • h-screen ignores mobile browser chrome — min-h-dvh is often better when available.
  • Collapsing margins still exist for non-flex block layout — prefer gap in flex/grid.

On this page