What is the difference between ‘margin’ and ‘padding’ in CSS

Margin and Padding both looks confusing at first but when you try to understand bottom line is While you have to deal with White Space around the element.

Padding is the space that’s inside the element between the element and the border. Padding goes around all four sides of the content and you can target and change the padding for each side with CSS.
Margin is the space between the border and next element. The space outside the border between it and the other elements is the margin. Just like padding, it’s possible to target all four sides of an element to change it’s margin.
To understand this example, please refer below Image:
Padding Vs Margin in CSS

Join Discussion

This site uses Akismet to reduce spam. Learn how your comment data is processed.