Web/API/IntersectionObserver/rootMargin

From Get docs

This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.


The IntersectionObserver interface's read-only rootMargin property is a string with syntax similar to that of the CSS margin property. Each side of the rectangle represented by rootMargin is added to the corresponding side in the root element's bounding box before the intersection test is performed. This lets you, for example, adjust the bounds outward so that the target element is considered 100% visible even if a certain number of pixels worth of width or height is clipped away, or treat the target as partially hidden if an edge is too close to the edge of the root's bounding box.

See The root element and root margin in Intersection Observer API for a more in-depth look at the root margin and how it works with the root's bounding box.

Syntax

var marginString = IntersectionObserver.rootMargin;

Value

A string, formatted similarly to the CSS margin property's value, which contains offsets for one or more sides of the root's bounding box. These offsets are added to the corresponding values in the root's bounding box before the intersection between the resulting rectangle and the target element's bounds.

The string returned by this property may not match the one specified when the IntersectionObserver was instantiated. The browser is permitted to alter the values

If rootMargin isn't specified when the object was instantiated, it defaults to the string "0px 0px 0px 0px", meaning that the intersection will be computed between the root element's unmodified bounds rectangle and the target's bounds.  The root element and root margin in Intersection Observer API describes how the rootMargin is used in more detail.

Specifications

Specification Status Comment
Intersection ObserverThe definition of 'IntersectionObserver.rootMargin' in that specification. Working Draft Initial definition

Browser compatibility

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

rootMargin

Experimental'

Chrome

Full support 51

Edge

Full support 15

Firefox Full support 55


Full support 55


No support 53 — 55

Disabled'

Disabled' From version 53 until version 55 (exclusive): this feature is behind the dom.IntersectionObserver.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

IE

No support No

Opera

Full support Yes

Safari Full support 12.1

Notes'

Full support 12.1

Notes'

Notes' rootMargin does not work with <iframe>s.

WebView Android

Full support 51

Chrome Android

Full support 51

Firefox Android

?

Opera Android

?

Safari iOS Full support 12.2

Notes'

Full support 12.2

Notes'

Notes' rootMargin does not work with <iframe>s.

Samsung Internet Android

Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.
See implementation notes.'
See implementation notes.
User must explicitly enable this feature.'
User must explicitly enable this feature.