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.

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!