Spacing

Spacing scale and usage conventions.

Scale

TokenrempxVisual
00rem0px
px0.0625rem1px
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 vs. Margin

Padding is the space inside an element, between its border and its content. It pushes content inward and is part of the element's clickable/visible area. Use padding to create breathing room within a component.

Margin is the space outside an element, between its border and its neighbours. It pushes adjacent elements away. Use margin to create separation between components.

A good rule of thumb: use padding for internal component spacing (how much room content has inside a card, button, or section) and margin for external layout spacing (how far apart two components sit from each other). In flex/grid layouts, prefer gap over margins — it avoids the double-spacing problem at edges.

html
{/* Padding — space inside the card */}
<div class="p-6 border rounded-lg">Card content</div>
 
{/* Margin — space between cards */}
<div class="mt-8">Next section</div>
 
{/* Gap — preferred for flex/grid children */}
<div class="flex gap-4">
<div>Item 1</div>
<div>Item 2</div>
</div>
11 lines of html code

Directional spacing

Tailwind provides directional variants for both padding and margin. Use these to control spacing on specific axes.

Vertical (top/bottom)

Use py-* for symmetric vertical padding, or pt-* / pb-* to target one side. For margin, use my-*, mt-*, mb-*.

html
{/* Symmetric vertical padding */}
<section class="py-12">Equal top and bottom</section>
 
{/* Asymmetric — more space above */}
<section class="pt-16 pb-8">More breathing room above</section>
 
{/* Vertical margin between sections */}
<div class="my-10">Spaced equally from siblings</div>
8 lines of html code

Horizontal (left/right)

Use px-* for symmetric horizontal padding, or pl-* / pr-* to target one side. For margin, use mx-*, ml-*, mr-*. For centering, mx-auto is the standard pattern.

html
{/* Symmetric horizontal padding */}
<div class="px-6">Content with side padding</div>
 
{/* Centered container */}
<div class="mx-auto max-w-5xl px-8">Centered content</div>
 
{/* RTL-safe: use logical properties */}
<div class="ps-4 pe-2">Start/end padding (flips for RTL)</div>
8 lines of html code

For layouts that must support RTL (Arabic), use logical properties: ps-* / pe-* (padding-inline-start/end) and ms-* / me-* (margin-inline-start/end) instead of pl-* / pr-*. These flip automatically when the page direction changes.

Guidelines

  • Use the scale — avoid arbitrary pixel values. Consistent spacing creates visual rhythm and makes responsive adjustments predictable.
  • Prefer gap — when spacing flex or grid children, use gap-* instead of adding margins to individual items.
  • Component padding — most components use p-3 or p-4 for internal padding. Cards and panels typically use p-6.
  • Section spacing — vertical spacing between page sections uses py-12 to py-20 depending on visual weight.

When in doubt, pick the next value up from the scale rather than the next value down. Generous whitespace improves readability.