The scroll-margin shorthand sets outsets around an element’s scroll snap area. When that element is snapped to or scrolled into view, the browser leaves that much space from the edge of the scrollport.
Two values. Like margin: first = top and bottom, second = left and right.
Larger vertical offset.40px clears more space on the block axis.
Smaller sides.8px is a light inset on the left and right.
Four values would be top, right, bottom, left in that order.
Edge Cases & Pitfalls
If the target still hides under a header, one of these is usually why.
target
Set it on the target, not the container
Put scroll-margin on the element you scroll to. For a container-wide inset, use scroll-padding instead.
layout
Not the same as margin
It does not push siblings apart. Neighbors keep their normal layout positions.
%
Percentages are invalid
Use lengths such as px, rem, or em. A percentage value is dropped.
end
Near the end of the scroll range
If there is not enough room to honor the offset, the browser stops as close as it can.
alias
Old name: scroll-snap-margin
Prefer scroll-margin. Some engines still recognize the older name as an alias.
Compatibility
Browser Support
scroll-margin is a browser CSS property for scroll targets. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
scroll-margin
Chrome 69+, Edge 79+, Firefox 90+, Safari 14.1+ / iOS 14.5+. Not supported in Internet Explorer.
97%Global support
Google Chrome69+
Full support
Mozilla Firefox90+
Full support
Apple Safari14.1+
Full support
Microsoft Edge79+
Full support
Opera56+
Full support
Samsung Internet10.1+
Full support
Internet ExplorerNo support
No support
scroll-marginWidely supported
Bottom line: Safe for modern sites. Prefer scroll-margin over the older scroll-snap-margin name. This is not a JavaScript runtime API.
Remember
Key Takeaways
Role: offset where a scroll target stops relative to the scrollport.
On the target. Use lengths only; percentages are invalid.
vs scroll-padding: margin on the item; padding on the container.
Sticky headers: match scroll-margin-top to the header height.
One line:scroll-margin keeps scroll targets out from under sticky UI — without changing layout.
Frequently Asked Questions
It adds an invisible outset around an element’s scroll snap area. When that element is scrolled into view or snapped to, the browser stops with that extra offset — useful under sticky headers.
margin changes layout spacing between boxes. scroll-margin does not move neighbors; it only changes where scrolling stops when the element is a scroll target.
scroll-margin is set on the target being scrolled to. scroll-padding is set on the scroll container to inset the scrollport.
Each longhand starts at 0, so the shorthand’s initial effect is no extra offset.
No. scroll-margin accepts length values only. Percentages are invalid.
It is Baseline Widely available: Chrome 69+, Edge 79+, Firefox 90+, Safari 14.1+. It is a browser CSS property, not a Node.js feature. Internet Explorer does not support it.