CSS Box Model

3. CSS Margins


          The margin property sets the space around an HTML element. This property can have a negative value which will result in overlapping of content. Margin will not be inherited by the child element. A shorthand property of margin can be used to set in one declaration the top, right, bottom and left margin, in this particular order. The auto value of this property will automatically set the margin left and right of the element equally.

  • margin-top – sets the top margin of an element. 
  • margin-bottom – sets the bottom margin of an element. 
  • margin-left – sets the left margin of an element.
  • margin-right – sets the right margin of an element.

Note: You cannot set the top and bottom margin (also padding) in an inline element. Only the left and right can be set since the inline element flows with the content on the page.