Easy Tutorial
❮ Pr Class Position Pr Class Float ❯

CSS margin Property

Example

Set the margins for all four sides of a p element:

p {
    margin: 2cm 4cm 3cm 4cm;
}

Property Definition and Usage

The margin shorthand property sets all the margin properties in one declaration. This property can have from one to four values.

Examples:

Note: Negative values are allowed.

Default value: 0
Inherited: no
Version: CSS1
JavaScript syntax: object.style.margin="10px 5px"

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property Chrome IE Firefox Safari Opera
margin 1.0 6.0 1.0 1.0 3.5

Property Values

Value Description
auto The browser calculates the margin.
length Specifies a margin in px, cm, etc. Default value is 0px.
% Specifies a margin in percent of the width of the containing element.
inherit Specifies that the margin should be inherited from the parent element.

Related Articles

CSS Tutorial: CSS Margin

❮ Pr Class Position Pr Class Float ❯