coderef

Intersection observerBaseline · Widely available

The IntersectionObserver API asynchronously observes changes in the intersection of a target element with an ancestor element or with a top-level document's viewport.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Mar 25, 2019. Widely available since Sep 25, 2021.

Browser support

DesktopChrome
1–57Not supported
58+Supportedsince Apr 19, 2017
Current: 155
Edge
12–15Not supported
16+Supportedsince Oct 17, 2017
Current: 154
Firefox
1–54Not supported
55+Supportedsince Aug 8, 2017
Current: 157
Safari
1–12Not supported
12.1+Supportedsince Mar 25, 2019
Current: 27
MobileChrome Android
18–57Not supported
58+Supportedsince Apr 25, 2017
Current: 155
Firefox Android
4–54Not supported
55+Supportedsince Aug 8, 2017
Current: 157
Safari iOS
1–12Not supported
12.2+Supportedsince Mar 25, 2019
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

JS
const observer = new IntersectionObserver((entries) => {
  for (const entry of entries) {
    if (entry.isIntersecting) {
      entry.target.classList.add("visible");
      observer.unobserve(entry.target);
    }
  }
}, { rootMargin: "0px 0px -10% 0px" });

document.querySelectorAll(".reveal").forEach((el) => observer.observe(el));

Feature detection

JS · check before using
if ("IntersectionObserver" in globalThis) {
  // IntersectionObserver is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (23). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
IntersectionObserver51155512.1515512.2
IntersectionObserver.IntersectionObserver51155512.1515512.2
IntersectionObserver.IntersectionObserver.options_root_parameter_Document81817614817914
IntersectionObserver.delay7479✕✕74✕✕
IntersectionObserver.disconnect51155512.1515512.2
IntersectionObserver.observe51155512.1515512.2
IntersectionObserver.root51155512.1515512.2
IntersectionObserver.rootMargin51155512.1515512.2
IntersectionObserver.scrollMargin1201201412612014126
IntersectionObserver.takeRecords51155512.1515512.2
IntersectionObserver.thresholds52155512.1525512.2
IntersectionObserver.trackVisibility7479✕✕74✕✕
IntersectionObserver.unobserve51155512.1515512.2
IntersectionObserverEntry51155512.1515512.2
IntersectionObserverEntry.IntersectionObserverEntry✕✕✕12.1✕✕12.2
IntersectionObserverEntry.boundingClientRect51155512.1515512.2
IntersectionObserverEntry.intersectionRatio51155512.1515512.2
IntersectionObserverEntry.intersectionRect51155512.1515512.2
IntersectionObserverEntry.isIntersecting58165512.1585512.2
IntersectionObserverEntry.isVisible7479✕✕74✕✕
Show 3 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
IntersectionObserverEntry.rootBounds51155512.1515512.2
IntersectionObserverEntry.target51155512.1515512.2
IntersectionObserverEntry.time51155512.1515512.2