DOM ResizeObserver Interface
ResizeObserver calls a function whenever an element changes size, which is useful for components that adapt to their own width rather than the window's.
Description
A ResizeObserver reports changes to the size of elements, whatever caused them: a window resize, new content, a CSS change or a sidebar opening. The callback receives entries with contentRect and the more detailed borderBoxSize and contentBoxSize.
Unlike the window resize event, it tracks individual elements. Many layout needs can now be met in CSS with container queries, but it's still useful for things like redrawing a chart when its container changes.
To avoid infinite loops, the browser limits how resize observers and layout interact: if your callback changes sizes in a way that triggers further resizes, the browser stops processing and reports a "ResizeObserver loop" error in the console, which is usually harmless but worth checking. Use unobserve() to stop watching an element and disconnect() to stop watching everything.
Example
Browser Support
The following information will show you the current browser support for the ResizeObserver interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





