Welcome to the Treehouse Community
Looking to learn something new?
MARIA Quadri2,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)
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!
Christof Baumgartner20,864 Points
There is a great stackoverflow discussion about this with examples: https://stackoverflow.com/questions/2189452/when-to-use-margin-vs-padding-in-css