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

Osama Mansour
Osama Mansour
1,411 Points

what is the function of margin and padding in web designing?

margin and padding

david Ramirez
david Ramirez
Courses Plus Student 2,798 Points

The function of the padding it generates space. For the margin it also generates space around elements.

2 Answers

Paul Allison
Paul Allison
2,468 Points

margin and padding give you control over the space inside and around your element...... between its content and border is padding ............and outside its border the margin.

you could use them to separate links or images inside an element .....PADDING

or to separate different elements on your page from each other .....MARGIN

http://www.w3schools.com/css/css_padding.asp

http://www.w3schools.com/css/css_margin.asp

copy and paste these links .

Mark Wilkowske
PLUS
Mark Wilkowske
Courses Plus Student 18,131 Points

Adding on to Paul's answer, if you have not heard about the Box Model then that will help understand margin & padding too. The CSS you write fits around HTML elements in a certain way - like a box.

Examples I use - for <p> I put 15px bottom margin on <p>'s because usually another <p> will follow and so that margin creates nice horizontal space between <p>s. For padding, if I have <li><a>home</a></li> I'll put padding on <a> if I want the link to appear like a button.

You can test margin/padding out here http://getbootstrap.com/css/ and in Firebug inspect .nav navbar-nav <li><a></a><li>