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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s