MyInternships.in

Spacing and Sizing

Padding and Margin

Spacing in Tailwind uses a consistent numeric scale where each step is 0.25rem (4px). Padding adds space inside an element; margin adds space outside it.


Directions and the scale

Suffix a side to target it: p-4 (all sides), px-4 (left+right), py-2 (top+bottom), pt-4 (top only). Margin works the same with m-, mx-, my-, mt- etc. The number is the scale step.

ClassValue
p-14px
p-28px
p-416px
p-624px
p-832px
Padding on the box, margin between boxes
Example
<div class="bg-slate-100 p-4 rounded-lg">
  <div class="bg-sky-500 text-white p-6 rounded mb-4">Padding 6, margin-bottom 4</div>
  <div class="bg-sky-500 text-white p-2 rounded">Padding 2</div>
</div>

Spacing children with space-*

space-y-4 adds vertical space between child elements automatically — no need to put margins on each child.

Even vertical rhythm with space-y
Example
<div class="space-y-3">
  <div class="bg-white p-3 rounded shadow">One</div>
  <div class="bg-white p-3 rounded shadow">Two</div>
  <div class="bg-white p-3 rounded shadow">Three</div>
</div>
💡

mx-auto centers a block element horizontally when it has a fixed or max width — the classic centering trick.

Related Tailwind Topics

Keep learning with these closely related lessons.