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 CSS Layout Basics Getting Started with CSS Layout Why Vertical Margins Collapse

abdirahman liban
PLUS
abdirahman liban
Courses Plus Student 2,163 Points

margin and padding confusion

after I watched many courses of html and css in treehouse I'm still confused about margin and padding

3 Answers

Erik S.
Erik S.
9,789 Points

Padding is applied to the inside of the border of your element so you can control how far the content is away from the border.

Margin is applied to the outside of the border of your element, so you can control how far the element is away from other elements.

Special usage: if you use a negative margin, you can pull the element closer to other elements. and also good to keep in mind: padding will increase the dimensions of your element, whereas margin won't.

John Satterfield
John Satterfield
13,695 Points

Erik Schmok explained the differences very well.

If you need further explanation and examples you can always reference the w3schools website on padding and margins here: http://www.w3schools.com/css/css_margin.asp http://www.w3schools.com/css/css_padding.asp http://www.w3schools.com/css/css_boxmodel.asp

Padding: Space in between the content and the content box edge.

Margin: Space set around the border box (content box + padding (optional) + border) relative to other elements.