Tailwind CSS Cheatsheet

Spacing and Sizing

Use this Tailwind CSS reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

The Spacing Scale

Tailwind uses a numeric scale where each step equals 0.25rem (4px at default root font size).

Steprempx
000
0.50.125rem2px
10.25rem4px
1.50.375rem6px
20.5rem8px
2.50.625rem10px
30.75rem12px
3.50.875rem14px
41rem16px
51.25rem20px
61.5rem24px
71.75rem28px
82rem32px
92.25rem36px
102.5rem40px
112.75rem44px
123rem48px
143.5rem56px
164rem64px
205rem80px
246rem96px
287rem112px
328rem128px
369rem144px
4010rem160px
4411rem176px
4812rem192px
5213rem208px
5614rem224px
6015rem240px
6416rem256px
7218rem288px
8020rem320px
9624rem384px

Padding

ClassCSS
p-{n}padding: {n} (all sides)
px-{n}padding-left: {n}; padding-right: {n}
py-{n}padding-top: {n}; padding-bottom: {n}
pt-{n}padding-top: {n}
pr-{n}padding-right: {n}
pb-{n}padding-bottom: {n}
pl-{n}padding-left: {n}
ps-{n}padding-inline-start: {n} (logical)
pe-{n}padding-inline-end: {n} (logical)
<div class="p-4">All sides 1rem</div>
<div class="px-6 py-3">Horizontal 1.5rem, vertical 0.75rem</div>
<div class="pt-8 pb-4 px-6">Individual sides</div>
<button class="px-4 py-2">Button padding</button>

Margin

Same suffixes as padding (m-, mx-, my-, mt-, mr-, mb-, ml-, ms-, me-).

Special valueCSS
m-automargin: auto
mx-automargin-left: auto; margin-right: auto
my-automargin-top: auto; margin-bottom: auto
-m-4margin: -1rem (negative margin)
-mt-2margin-top: -0.5rem
<!-- Center a block element -->
<div class="max-w-2xl mx-auto">Centered</div>

<!-- Negative margin overlap -->
<div class="mt-8 -mb-4">...</div>

<!-- Auto margin pushes items in flex -->
<div class="flex">
  <span>Left</span>
  <span class="ml-auto">Right</span>
</div>

Space Between (Flex/Grid children shortcut)

Adds margin to all children except the first (avoids adding gap to the parent).

ClassCSS
space-x-{n}margin-left on all children except first
space-y-{n}margin-top on all children except first
space-x-reversefor flex-row-reverse
space-y-reversefor flex-col-reverse
<div class="flex space-x-4">
  <button>A</button>
  <button>B</button>
  <button>C</button>
</div>

Prefer gap-* on the flex/grid container — it's more predictable and supports wrapping correctly.

Width

ClassCSS
w-0width: 0
w-pxwidth: 1px
w-{n}width: {spacing scale}
w-1/2width: 50%
w-1/3width: 33.333%
w-2/3width: 66.667%
w-1/4width: 25%
w-3/4width: 75%
w-1/5w-4/520%–80%
w-1/6w-5/616.67%–83.33%
w-1/12w-11/12grid-friendly fractions
w-fullwidth: 100%
w-screenwidth: 100vw
w-svwwidth: 100svw
w-dvwwidth: 100dvw
w-minwidth: min-content
w-maxwidth: max-content
w-fitwidth: fit-content
w-autowidth: auto
w-[347px]width: 347px

Min-Width / Max-Width

Min-Width

ClassCSS
min-w-0min-width: 0
min-w-pxmin-width: 1px
min-w-{n}spacing scale
min-w-fullmin-width: 100%
min-w-minmin-width: min-content
min-w-maxmin-width: max-content
min-w-fitmin-width: fit-content

Max-Width

ClassCSS
max-w-nonemax-width: none
max-w-0max-width: 0
max-w-xsmax-width: 20rem
max-w-smmax-width: 24rem
max-w-mdmax-width: 28rem
max-w-lgmax-width: 32rem
max-w-xlmax-width: 36rem
max-w-2xlmax-width: 42rem
max-w-3xlmax-width: 48rem
max-w-4xlmax-width: 56rem
max-w-5xlmax-width: 64rem
max-w-6xlmax-width: 72rem
max-w-7xlmax-width: 80rem
max-w-fullmax-width: 100%
max-w-screen-smbreakpoint-based max
max-w-minmax-width: min-content
max-w-maxmax-width: max-content
max-w-fitmax-width: fit-content
max-w-prosemax-width: 65ch
max-w-[800px]arbitrary

Height

ClassCSS
h-0height: 0
h-pxheight: 1px
h-{n}spacing scale
h-1/2height: 50%
h-fullheight: 100%
h-screenheight: 100vh
h-svhheight: 100svh (small viewport)
h-dvhheight: 100dvh (dynamic viewport)
h-lvhheight: 100lvh (large viewport)
h-minheight: min-content
h-maxheight: max-content
h-fitheight: fit-content
h-autoheight: auto
h-[500px]arbitrary

Min-Height / Max-Height

Same pattern — min-h-* and max-h-* with the same values.

<!-- Full-height page with scrollable main -->
<div class="flex flex-col min-h-screen">
  <header>...</header>
  <main class="grow overflow-y-auto">...</main>
</div>

Size (Width + Height Shorthand)

Sets both width and height simultaneously (Tailwind v3.3+).

ClassCSS
size-{n}width: {n}; height: {n}
size-fullwidth: 100%; height: 100%
size-autowidth: auto; height: auto
size-fitwidth: fit-content; height: fit-content
size-[48px]arbitrary square
<!-- Icon button, avatar, dot indicator -->
<button class="size-10 rounded-full flex items-center justify-center">
  <svg class="size-5">...</svg>
</button>

<img class="size-12 rounded-full object-cover" src="avatar.jpg" alt="">
<span class="size-2 rounded-full bg-green-500"></span>

Arbitrary Spacing

<div class="mt-[72px] px-[1.625rem] w-[calc(100%-2rem)]">...</div>

Logical Properties

Use logical (RTL-aware) classes when building internationalized UIs:

ShorthandLogical startLogical end
ms-* / me-*margin-inline-startmargin-inline-end
ps-* / pe-*padding-inline-startpadding-inline-end
start-* / end-*inset-inline-startinset-inline-end