CSS margin-top property

Definition and usage

The marginTop property sets the top outer margin of the element.

Note:Negative values can be used.

See also:

CSS Tutorial:CSS Margin

HTML DOM Reference Manual:marginTop property

Example

Set the top outer margin of the p element:

p
  {
  margin-top:2cm;
  }

Try it yourself

(More examples can be found at the bottom of the page)

CSS syntax

margin-top: length|auto|initial|inherit;

Property value

Value Description
auto The top outer margin set by the browser.
length Specifies a fixed top outer margin. The default value is 0.
% Specifies the top outer margin as a percentage of the width of the containing element.
inherit Specifies that the top outer margin should be inherited from the parent element.

Technical details

Default value: 0
Inheritance: no
Version: CSS1
JavaScript syntax: object.style.marginTop="10px"

More examples

Set the top outer margin of text to 1
This example demonstrates how to set the top margin of text using centimeter values.
Set the top outer margin of text to 2
This example demonstrates how to set the top margin of text using percentage values.

Browser support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome IE / Edge Firefox Safari Opera
1.0 6.0 1.0 1.0 3.5