What is the difference between Margin and Padding? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between Margin and Padding?

I find their properties to be similar.

17th Oct 2017, 3:43 PM
Raktim Kashyap
Raktim Kashyap - avatar
4 Answers
+ 8
Imagine a box with borders, the area *outside* the border is the margin while the area *inside* is the padding. If you have 2 boxes side-by-side, increasing the margin will separate the two further away but it's not the case for padding as it will push the content inside the box towards the centre until it collapse.
17th Oct 2017, 4:16 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
margin is not clickable padding is clickable margin push your content.no width or height have been increased padding push your content by increase width or height offset https://code.sololearn.com/WdJWwRTqtRwD/?ref=app
17th Oct 2017, 4:19 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 1
margin and padding are the two most commonly used properties for spacing-out elements. A margin is the space outside something, whereas padding is the space inside something. Change the CSS code for h2 to the following: h2 { font-size: 1.5em; background-color: #ccc; margin: 20px; padding: 40px; }
7th Mar 2018, 8:17 PM
Amit Viramgami
Amit Viramgami - avatar