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!
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

MARIA Quadri
2,572 PointsWhat is the difference between padding and margin in CSS
Don't they both just add space? I can't figure out the difference. ( I'm also very new to this so maybe i haven't written enough code to visually see the difference)
2 Answers
Kelly Castle
10,547 PointsThis took me a while to figure out too- I'm a visual learner so I had to play around with it to understand. BUT- margin is the outer space of an element, so think of it as pushing things away from the element, while padding is the inner space of the element.
Think of it as a picture frame- increasing margin would expand space away from the outside of the frame, while increasing padding would expand the inner space of the frame, making it a larger frame.
That's how I think of it- hopefully that helps!

MARIA Quadri
2,572 PointsThis picture frame example makes so much sense - thank you! :)

Christof Baumgartner
20,864 PointsThere is a great stackoverflow discussion about this with examples: https://stackoverflow.com/questions/2189452/when-to-use-margin-vs-padding-in-css

MARIA Quadri
2,572 PointsI'll def check out this discussion thank you!
Kelly Castle
10,547 PointsKelly Castle
10,547 PointsGlad to help! :)