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 Layout Techniques Float Layout The Float Clearfix

margin-right:0; and margin:initial


I noticed that in media queries we sometimes set elements to Zero or intial. What is the difference between margin:initial and marging-right:0


4 Answers

Chris Shaw
Chris Shaw
26,662 Points

Hi orange sky,

It depends on the element, some elements have default margins therefore setting a zero margin might be different from initial which inherits the default offset of the browser, generally you wouldn't use initial on margins as there is not typical scenario where you need to reset an elements margins.

Jacky Giang
Jacky Giang
10,596 Points

Hi there!

Each CSS property has an 'initial' value unaffected by the browser default. This value is defined in CSS specifications. So, setting margin to 'initial' will revert all four margins (top, right, bottom, left) back to its CSS specification. Click here for some examples on how 'initial' is used.

Now, that's true if its value is not inherited from a parent element... It can get confusing in this inherited scenario, but click here if you want to read more!

'margin-right: 0' only sets the element's right margin to 0.

Hello Jacky,

Would an element with a margin-right:0 look different from margin:right:initial?

In fact, do you know a direct link to view the intial values of most major elements?


Thanks Chris! That was very specific!

Chris, can you please write a one word response to this post under "Add an answer", that way I can vote.

**Add an answer is at the bottom of this page.

Thanks always for your help!!!