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

MARIA Quadri
MARIA Quadri
2,572 Points

What 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)

Glad to help! :)

2 Answers

This 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
MARIA Quadri
2,572 Points

This picture frame example makes so much sense - thank you! :)

MARIA Quadri
MARIA Quadri
2,572 Points

I'll def check out this discussion thank you!