margin

Description »

Margin is the shorthand property for defining the distance of an element from other elements along all sides.

Browser Compatibility
IE FF GC S O

Possible Values »

  • margin: top right bottom left;
  • Sets the individual margins for each side.
  • margin: top-bottom right-left;
  • Two values can be passed instead of four. The first sets the top and bottom; the second sets the right and left.
  • margin: top right-left bottom;
  • If three values are passed, the first sets the top margin, the second sets the right and left, and the last sets the bottom.
  • margin: all;
  • A single value will set all four margins for the selected element.
  • margin: auto;
  • The browser calculates its own margins, usually centering the block.
  • margin: inherit;
  • The element inherits the margin settings of the parent element.

Details »

Margin adjust spacing between blocks and elements. If I had a div block, the margin of that div block adjusts its distance from all the elements around it.

Margin values can be measured by pixels (px), em, or percentage (%).

This property is used to define all of the margins for an element. You can access individual sides as well:

In Practice »

Results CSS
Try it! at The CSS Zone Sandbox
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License