Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS margin-top property

CSS margin-top property

Example

Set the top margin of a p element:

p

{

margin-top:

2

cm

;

}

Try it »


Property definition and usage

The margin-top property sets the top margin of an element.

Note: Negative values are allowed.

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

Browser support

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

property
margin-top 1.0 6.0 1.0 1.0 3.5

Attribute values

Value Description
auto The browser sets the top margin.
length Defines a fixed top margin. The default value is 0.
% Defines a top margin as a percentage of the parent element's total width.
inherit Specifies that the top margin should be inherited from the parent element.

Related Articles

CSS Tutorial: CSS Margin