CSS scroll-margin Property
Description
The scroll-margin property controls the offset used by the browser when bringing an element into view via scrolling actions (for example, fragment navigation, programmatic scrolling, or snap alignment). It does not change the element’s layout or its visual spacing in the document flow — instead it adjusts the point within the scrollport at which the element is considered "in view." In practice this means you can shift the final scroll position so the target element stops some distance away from the edge of its scroll container (useful for avoiding fixed headers or creating consistent breathing room around focused items) without altering actual margins in the layout.
This adjustment is applied to the element being scrolled to, not to the scroll container. When used together with CSS Scroll Snap behavior, the effective snap destination results from a combination of the element’s alignment rules and its scroll-margin. For example, the element’s snap alignment setting (scroll-snap-align) determines which edge of the element should line up with the scrollport, while scroll-padding on the container changes the scrollport’s inset; scroll-margin shifts the element’s target position relative to that final alignment. Because these properties act on different parts of the calculation — the element versus the container — they are complementary tools for fine-tuning scroll behavior.
The property operates along the block and inline axes, so you can influence vertical and horizontal scroll positioning independently. It’s also honored by various scrolling mechanisms: fragment links (the :target jump), element.scrollIntoView() and other programmatic scrolls, and snap alignment — and it interacts naturally with smooth scrolling behavior (scroll-behavior) so the adjusted target will be reached smoothly when smooth scrolling is enabled. Keep in mind that because scroll-margin is only used by the scrolling algorithm, it doesn’t affect hit-testing, painting, or how other elements flow around the target.
In practical use, scroll-margin is a reliable way to account for UI chrome (fixed headers, sticky bars) or to create consistent spacing when bringing arbitrary targets into view, without having to restructure the document or add spacer elements. Set it on the elements that will be targeted (anchors, focus targets, snap children) so individual items can define their own scroll offset. Also note that the property only matters when the element participates in a scrollable context; if the element isn’t within a scrollable ancestor for the axis in question, the property has no visible effect.
Definition
- Initial value
- See individual properties
- Applies to
- all elements
- Inherited
- no
- Computed value
- See individual properties
- Animatable
- by computed value type
- JavaScript syntax
- object.style.scrollMargin
Interactive Demo
Syntax
scroll-margin: <length>{1,4}
Values
- <length>An outset from the corresponding edge of the scroll container.
Example
Browser Support
The following information will show you the current browser support for the CSS scroll-margin property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
