Back to CSS1 Reference | CSS1 Properties
Prev list-style-type | Next margin-bottom


Property
margin
Values
<length>, <percentage>, auto
Initial
not defined for shorthand properties
Inherited
no

The 'margin' property is a shorthand property for setting 'margin-top', 'margin-right', 'margin-bottom' and 'margin-left' at the same place in the style sheet.

If four length values are specified they apply to top, right, bottom and left respectively. If there is only one value, it applies to all sides, if there are two or three, the missing values are taken from the opposite side.

      BODY { margin: 2em } /* all margins set to 2em */
      BODY { margin: 1em 2em } /* top & bottom = 1em, right & left = 2em */
      BODY { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */

The last rule of the example above is equivalent to the example below:

      BODY {
      margin-top: 1em;
      margin-right: 2em;
      margin-bottom: 3em;
      margin-left: 2em;        /* copied from opposite side (right) */
      }

Negative margin values are allowed, but there may be implementation-specific limits.