The margin-top property sets the margin area on the top of an element. A positive value moves the element farther from neighbors above; a negative value pulls it closer.
It is part of the box model (outside the border), is not inherited, and has no effect on non-replaced inline elements such as <span>. Prefer margin-block-start when you want spacing that follows writing mode.
Baseline · Widely available.
Not deprecated. Core length, percentage, and auto values work across modern browsers.
Syntax
CSS Syntax
syntax.css
margin-top:<length> | <percentage> | auto | inherit;
Example: margin-top: 1.5rem;. Values may be positive, zero, or negative.
Negative length. The top margin becomes less than zero.
The box moves up. Content can overlap if the value is large enough.
Use sparingly. Prefer padding, gap, or positive margins for everyday layout.
Check stacking and click targets when boxes overlap.
Edge Cases & Pitfalls
If the gap looks wrong or missing, check these first.
collapse
Vertical margins can collapse
A block’s margin-bottom and the next block’s margin-top may combine into one gap — often the larger value, not the sum.
inline
No effect on non-replaced inline
MDN: margin-top does not affect elements like <span>. Use a block, inline-block, or flex/grid item instead.
percent
% is based on width
Even for top margin, percentages resolve against the containing block’s inline size (width in horizontal writing modes).
vs
margin-top vs padding-top
Use padding-top for inner space (backgrounds extend into padding). Use margin for space between separate boxes.
logical
Physical top vs block-start
For multilingual or vertical layouts, prefer margin-block-start so spacing follows writing mode.
Compatibility
Browser Support
margin-top is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
margin-top
Length, percentage, and auto values work in all modern browsers and older engines.
99%Browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
OperaAll modern versions
Full support
Samsung InternetSupported
Full support
Internet ExplorerSupported
Full support
margin-topWidely supported
Bottom line: Safe for everyday vertical spacing. Remember collapse and the %/width rule. It is not a runtime API.
Remember
Key Takeaways
Role: outer space above an element’s border.
Initial:0. Not inherited.
Percentages use containing-block width.
Collapse can merge adjacent vertical margins.
One line:margin-top pushes space above a box — outside the border, after the previous element.
Frequently Asked Questions
It sets the outer space above an element, outside its border. A positive value pushes the element down from content above; a negative value pulls it closer.
The initial value is 0. There is no top margin until you set one.
margin-top is outside the border, between elements. padding-top is inside the border, between the border and the content.
margin-top always targets the physical top edge. margin-block-start follows writing mode, so it maps to the block-start side in vertical or RTL layouts.
Yes. Adjacent vertical margins between block boxes can collapse into one. The used gap is often the larger of the two margins.
It is Baseline Widely available. It is a browser CSS box-model property, not a Node.js runtime feature.