margin-top - HTML CSS CSS Property

HTML CSS examples for CSS Property:margin-top

Description

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

The following table summarizes the margin-top Property.

Item Value
Default value: 0
Applies to:All elements except those with table display types other than table-caption, table, and inline-table. It also applies to ::first-letter.
Inherited: No
Animatable: Yes.

Syntax

The syntax of the property is as follows:


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

Property Values

The following table describes the values of this property.

Value Description
length A length value in px, pt, cm, em, etc. Negative values are allowed.
percentage The margin in percentage. The percentage is calculated with respect to the width of the element's containing block.
auto The browser will calculate the margin for the specified element.
initialSets this property to its default value.
inherittake the value of its parent element margin-top property.

The example below shows the margin-top property.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS margin-top Property</title>
  <style type="text/css">
    h1 {<!--from w  ww. ja v  a  2s . c om-->
        margin-top: 25px;
    }
    p {
        margin-top: 50px;
    }
</style>
 </head>
 <body>
  <h1>This is a heading</h1>
  <p>This is a paragraph.</p>
 </body>
</html>

Related Tutorials