Tailwind css tutorial Hindi #6 Mastering Margin and Padding
All about Margin and Padding.?
- How to apply margin and padding on all sides
- Margin/padding on all sides
- Use m- for margin and p- for padding.
- Examples:
- Margin on all sides:
- m-4 → margin on top, right, bottom, left.
- Padding on all sides:
- p-4 → padding on top, right, bottom, left.
- You just change the number for more or less space: 0, 0.5, 1, 1.5, 2, 3, 4, 5, ... etc.
•How to apply margin and padding on vertical and Horizontal Side.
Vertical and horizontal sides
• Vertical (top + bottom):
• Margin: my-4
• Padding: py-4
• Horizontal (left + right):
• Margin: mx-4
• Padding: px-4
Think:
• y → up–down
• x → left–right
•How to apply margin and padding on single side
Single side (top, right, bottom, left)
Margin:
- Top: mt-4
- Right: mr-4
- Bottom: mb-4
- Left: ml-4
Padding:
- Top: pt-4
- Right: pr-4
- Bottom: pb-4
- Left: pl-4
Pattern is same: first letter m or p, then side letter, then value.
•Apply margin and padding on span
<span> is inline by default, but Tailwind utilities still work.
Example:
<span class="m-2 p-2 bg-yellow-200">Text</span>
If you want it to behave more like a box (for layout), you can also add inline-block or block:
<span class="inline-block m-2 p-2 bg-yellow-200">Text</span>
• Interview questions.
How to apply 1 px margin and padding
margin and padding different in tailwind 3 and 4 version