{{CSSRef}}
Summary
The margin-top
CSS property of an element sets the margin space required on the top of an element. A negative value is also allowed.
This property has no effect on non-replaced inline elements, like {{HTMLElement("tt")}} or {{HTMLElement("span")}}.
{{cssinfo}}
Syntax
/* <length> values */ margin-top: 10px; /* An absolute length */ margin-top: 1em; /* A length relative to the text size */ margin-top: 5%; /* A margin relative to the nearest block container's width */ /* Keyword values */ margin-top: auto; /* Global values */ margin-top: inherit; margin-top: initial; margin-top: unset;
Values
<length>
- Specifies a fixed width. See {{cssxref("<length>")}} for possible values.
<percentage>
- A {{cssxref("<percentage>")}} always relative to the width of the containing block.
auto
- See {{cssxref("margin")}}.
Formal syntax
{{csssyntax}}
Examples
.content { margin-top: 5%; } .sidebox { margin-top: 10px; } .logo { margin-top: -5px; } #footer { margin-top: 1em; }
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Box', '#the-margin', 'margin-top')}} | {{Spec2('CSS3 Box')}} | No significant change |
{{SpecName('CSS3 Transitions', '#animatable-css', 'margin-top')}} | {{Spec2('CSS3 Transitions')}} | Defines margin-top as animatable. |
{{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-top')}} | {{Spec2('CSS2.1')}} | Removes its effect on inline elements. |
{{SpecName('CSS1', '#margin-top', 'margin-top')}} | {{Spec2('CSS1')}} | Initial definition |
Browser compatibility
{{CompatibilityTable()}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1")}} | 3.0 | 3.5 | 1.0 (85) |
auto value |
1.0 | {{CompatGeckoDesktop("1")}} | 6.0 (strict mode) | 3.5 | 1.0 (85) |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoMobile("1")}} | 6.0 | 6.0 | 1.0 |