Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Difference between Margin and Padding

I just want to know in simple English what is the difference between padding and margin in CSS?

2 Answers

To explain Jacob's answer in a bit more detail: All elements on a page are made of content in a 'box' of some sort.

Margin is the distance between the different boxes (outside of the box) and padding is the distance between the box itself and the content inside it (inside the box).

Margin is generally useful for adding space between objects while padding is good for things like adding space between the edges of a button and the text inside it or just indenting text so it's not pressed up to the edge.

in the most simplistic way, the difference between margin and padding is, margin is the space outside of, or in between elements, and Padding is the space inside between the content and the border of the element. I hope this helps.