CSS scroll-margin-top Property
Description
The scroll-margin-top property defines an invisible offset that the browser uses when bringing an element into view through scrolling (for example via fragment navigation, focus, or programmatic scrolling methods). Instead of moving the element in the page layout, it adjusts the position at which that element is considered "in view" relative to the scrolling container’s start edge, effectively creating a buffer above the element so the element can appear lower in the viewport when scrolled to. This makes it a scrolling-only adjustment: the visual layout, hit testing, and document flow remain unchanged while the scroll target is shifted.
A common practical use for scroll-margin-top is to prevent anchored headings or focused inputs from being hidden under fixed-position headers. By applying the property to the target elements, you tell the browser to stop the scrolled-to position short of the element’s actual top edge so the element appears below the header. If you need to affect the container’s visible scrollport rather than individual elements, consider changing the container’s snapport padding via scroll-padding-top. For setting a consistent offset across multiple axes you can use the shorthand scroll-margin, while differences between this scrolling offset and normal layout displacement can often be clarified by comparing it with margin-top, which physically moves elements in the flow.
Interaction with other scroll-related behaviors is worth noting: scroll-margin-top influences where elements land when snapping behavior is in play, so it works together with properties that control snap alignment like scroll-snap-align. It also changes the endpoint for smooth or instantaneous programmatic scrolls (see scroll-behavior for how scrolling animations behave), because the browser computes the final offset using the scroll margin. Best practice is to apply scroll-margin-top to the elements that serve as anchors or navigation targets (headings, sections, form controls) rather than globally, so you get predictable offsets only where needed without affecting other interactions.
Definition
- Initial value
- 0
- Applies to
- all elements
- Inherited
- no
- Computed value
- as specified
- Animatable
- by computed value type
- JavaScript syntax
- object.style.scrollMarginTop
Interactive Demo
Syntax
scroll-margin-top: <length>
Values
- <length>An outset from the bottom edge of the scroll container.
Example
Browser Support
The following information will show you the current browser support for the CSS scroll-margin-top 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
