165 of 313 menu

The margin-top property

The margin-top property sets a margin at the top of an element. The value of the property is any size units or the key property auto, which allows the browser to independently calculate the element margin.

Syntax

selector { margin-top: value; }

Example

Let's give the block the 50px top margin:

<div id="parent"> <div id="elem"></div> </div> #parent { border: 1px solid green; display: inline-block; } #elem { margin-top: 50px; border: 1px solid red; width: 100px; height: 100px; }

:

See also

  • the margin-bottom property,
    that sets a bottom margin
  • the margin-left property
    that sets a left margin
  • the margin-right property
    that sets a right margin
  • the margin property
    that is a shorthand for a margin
  • the padding property
    that sets a padding
bycshiplaz