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 CSS Selectors Selectors - Beyond the Basics DRY CSS

Shahar Golan
Shahar Golan
819 Points

margin: 0 auto 2em;

What the 0 and the "auto means?

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Shahar,

When using the margin shorthand property with 3 values, they represent the following:

margin: top left/right bottom;

Regarding your question, the zero simply means that you are removing the margin from the top of the element.

"Auto", means the browser will automatically calculate the value for the left and right margins. This is particularly useful when you want to center a block level element inside it's container.

Hope this helps.