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 CSS Basics (2014) Basic Selectors Intro to Selectors

{ margin: 0; padding: 0; } what is the exact meaning of this?

w

3 Answers

John Domingo
John Domingo
9,058 Points

If you take a look at the CSS Box Model, you can think of any HTML element as a set of boxes. The content box, for example, would be the text or image that is the actual visible content of the element. The border, which can be made visible or invisible, is the "box" that wraps around the content box (although it doesn't have to be rectangular like the "box" name implies.

CSS Box Model

Padding and margin are invisible clearing areas inside and outside the border.

Padding is the space between the border and the content so that if you have text in an element, the padding helps to make sure the text does not flush against border. Just like an actual box full of contents (such as a package you might want to ship out), you can add foam peanuts, or padding, around the contents so that it doesn't touch the sides of the (border) box.

For zero padding, imagine putting a box into a box where the inner box is just slightly smaller so it fits perfectly. There is no space between the inner (content) box and the outer (border) box so there is zero padding.

Box Packaging

Margin is just the space outside the border. This is important for how you want your element to appear when other elements are nearby. If margin is zero, other elements (inline, above and below) will be be flush against your element.

I recommend these two stages The Box Model stage in the CSS Foundations Course (Web Design track) and The Box Model stage in the CSS Basics Course (Front-End Web Development track).

nice explanation dude! :clap:

Zach Elkins
Zach Elkins
9,602 Points

The main reason this is used is because sometimes the browser will apply it's default margin/padding to elements, and in a case where you do not want there to be any margin or padding space around an element you will want to define that there is no margin or padding.

* {
 margin: 0;
 padding: 0;
}

Resets the pages default margin and padding for the entire html file. This will allow you to have more control when you are styling specific elements.

It makes sets it so there is no space around the outside of the selector (margin) or between the border and contents (padding);