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

margin-right:0; and margin:initial

Hello,

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

Thanks

4 Answers

Chris Shaw
Chris Shaw
26,676 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?

Cheers!

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!!!