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

HTML How to Make a Website CSS: Cascading Style Sheets Take a Mobile-First Approach

Css query about margins and paddings

I think the video is not intuitive enough about what margins and padding really is. Can someone please explain in context of an html element and the browser width? Also I wanna know what does the value 'auto' do ? An example would be appreciated. Thanks in advance !

1 Answer

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

Elements are represented as box model with default CSS styling.

It has 4 layers: content - padding - border - margin.

In W3C specification, only "content" represent the real width of the content where in IE's model, everything up to border is considered width. In other word, in W3C model explicit padding and border adds up with content and form width where in IE everything under margin is considered a width. This is behavior can be used inter-changeably by setting box-sizing property to content-box(W3C) or border-box(IE).

Think about padding as extension of content's width. Border as separation between your content and margin. Margin as a separation between different elements.

Primitive way to test this is to use developer tool's inspect option or applying background-color with different padding and margins.