1. Technology



margin Description:

The margin property is a shorthand tag to define all the margins of an element.

margin in CSS Versions:

margin Syntax:

margin: [ <length> | <percentage> | auto ]{1,4}
margin: <margin-top> <margin-right> <margin-bottom> <margin-left>

  • length
    A specific length (include unit of measure).
  • percentage
    A percentage of the height of the closest block-level ancestor.
  • auto
    Allows the user-agent to define the margin based on inheritance and pre-set user-agent rules.

margin Initial Value:

Not defined

margin Applies To:

All elements.

margin Inheritance:

This property is not inherited.

margin Browser Support:

margin Examples:

set all margins

<p style="margin : 2em;">
 This paragraph has a 2 em margin on all sides.

set top and bottom the same and right and left the same

<p style="margin : 2em 1em;">
 This paragraph has a 2 em margin on the top and bottom and a 1em margin on the right and left.

margin Special Notes:

  • Negative values are permitted, but may be affected by implementation limits.
  • If only 3 values are listed, the left margin is assumed to be the same as the right.

More margin Information:

©2014 About.com. All rights reserved.