Favorites

DOM IntersectionObserver Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
IntersectionObserver
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

IntersectionObserver tells you when an element enters or leaves the viewport (or another element), for lazy loading, infinite scrolling and scroll animations.

Description

An IntersectionObserver reports when target elements start or stop overlapping the viewport, or a chosen ancestor element. The callback receives entries with isIntersecting, intersectionRatio and the element's position. The threshold option sets how much must be visible, and rootMargin grows or shrinks the area being watched.

It is far more efficient than checking positions in a scroll listener. Typical uses are lazy-loading content, infinite scrolling, pausing off-screen videos and triggering animations as elements appear. Images can often use the simpler loading="lazy" attribute instead.

Each entry also includes boundingClientRect, intersectionRect and rootBounds, which give the exact positions involved, and time, which records when the change happened. The callback runs once when you start observing an element, reporting its initial state, and then each time a threshold is crossed. Call unobserve() once an element no longer needs watching, such as after its content has loaded.

Example

<div style="height:300px">Scroll down</div>
<div id="target" style="height:80px">Target</div>
<div style="height:300px"></div>
const target = document.getElementById('target');
const io = new IntersectionObserver(entries => {
  entries.forEach(e => {
    console.log('visible:', e.isIntersecting);
    target.style.background = e.isIntersecting ? '#bbf7d0' : '#fecaca';
  });
}, { threshold: 0.5 });
io.observe(target);
console.log('Scroll the frame to see changes');

Browser Support

The following information will show you the current browser support for the IntersectionObserver interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee