Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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