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

I'm still confuse between margin and padding. What's the difference?

Please enlighten me in a simple way. Thanks! :) Because I'm still confuse between padding and margin. What's their difference? when will you use padding? when will you use margin?

Thanks!!

3 Answers

Good question, yes there is a difference, and has to do with the box model. Once you understand the box model, you'll understand the difference, and when you should use margin or padding.

Padding is inside of the box model, margin is outside of the box model. Check this out: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model

Wow! Thanks! The link you provided was very helpful! Cheers! :)

If you think of a box, margins are the spaces outside of the box. Padding is the spacing inside of a box. So if I have text in the box and I move the margins the entire box moves. If I add padding to the box, the entire box doesn't move but the space inside the box gets larger.

Thanks for clearing that up Latoya! :)