- Padding:
p-4,px-6(left/right),py-2(top/bottom),pt-8… - Margin:
m-4,mx-auto(centre),mt-6, negative-mt-2 - Space between children:
space-y-4,space-x-2
The scale is based on 0.25rem: 1 = 4px, 4 = 16px, 8 = 32px.
Padding, margin and space between.
✍️ 3 exercises + code challenge in this lessonp-4, px-6 (left/right), py-2 (top/bottom), pt-8…m-4, mx-auto (centre), mt-6, negative -mt-2space-y-4, space-x-2The scale is based on 0.25rem: 1 = 4px, 4 = 16px, 8 = 32px.
Mastering Tailwind Spacing helps you write clean and reliable Tailwind CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
<script src="https://cdn.tailwindcss.com"></script>
<div class="max-w-sm mx-auto mt-6 space-y-3">
<div class="p-2 bg-cyan-100">p-2</div>
<div class="px-8 py-4 bg-cyan-200">px-8 py-4</div>
<div class="p-6 bg-cyan-300">p-6</div>
</div>
Check what you learned in “Tailwind Spacing”.
Centre a block horizontally.
<div class="max-w-md ">...</div>
How many pixels is p-4 by default?
Give the box padding p-6 and margin-top mt-4.
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services