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

Margin Vs. Padding

I don't know why but I can't get a grip on when to use Margin versus when to use Padding.

Can anyone give me a simple way to decide or maybe a mantra you use that has helped you remember when to use them?

It's just not sticking in the noggin. :P

Thanks.

1 Answer

Say you have 2 red boxes next to each other. Both have text within them. If you want to move the boxes apart, you'd use margin. If you want to increase the distance between the edge of one of the boxes and the text inside, you'd use padding.

What we're dealing with is the css box model. Take a quick look at this article, it explains it in more detail;

http://css-tricks.com/the-css-box-model/

Hope that helps a bit!

Good stuff, thanks Ben!