Lesson 29 +20 XP

Spacing & Size Cheatsheet

Spacing & Sizing Cheatsheet

The dynamic spacing scale in v4 means every integer works for margin, padding, width, height, gap, and more.

Quick spacing reference

nrempx
10.25rem4px
20.5rem8px
30.75rem12px
41rem16px
61.5rem24px
82rem32px
123rem48px
164rem64px

Margin & padding patterns

GoalClasses
All sides 1remp-4
Horizontal 1.5rempx-6
Vertical 0.5rempy-2
Only bottommb-8
Negative overlap-mt-6
Center blockmx-auto

Sizing patterns

GoalClasses
Half widthw-1/2
Full widthw-full
Full heighth-full
Full viewport heightmin-h-screen (mobile-safe: min-h-dvh)
Fixed 3remsize-12
Containermax-w-2xl mx-auto px-4

Gap

  • gap-4 (both axes), gap-x-2, gap-y-6.

Space between siblings

The space-* utilities add margins to all but the first child:

<div class="space-y-4">
  <div>Item</div>
  <div>Item</div>
</div>

space-y-4 adds margin-block-start to all but the first element.

TL;DR

  • Every integer works on the spacing scale.
  • mx-auto centers; max-w-* constrains.
  • size-* sets both dimensions.
  • space-y-* spaces stacked siblings.