ResizeObserverEntry

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.

* Some parts of this feature may have varying levels of support.

The ResizeObserverEntry interface represents the object passed to the ResizeObserver() constructor's callback function, which allows you to access the new dimensions of the Element or SVGElement being observed.

Instance properties

ResizeObserverEntry.borderBoxSize Read only

An array of objects containing the new border box size of the observed element when the callback is run.

ResizeObserverEntry.contentBoxSize Read only

An array of objects containing the new content box size of the observed element when the callback is run.

ResizeObserverEntry.devicePixelContentBoxSize Read only

An array of objects containing the new content box size in device pixels of the observed element when the callback is run.

ResizeObserverEntry.contentRect Read only

A DOMRectReadOnly object containing the new size of the observed element when the callback is run. Note that this is now a legacy property that is retained in the spec for backward-compatibility reasons only.

ResizeObserverEntry.target Read only

A reference to the Element or SVGElement being observed.

Note: The content box is the box in which content can be placed, meaning the border box minus the padding and border width. The border box encompasses the content, padding, and border. See The box model for further explanation.

Instance methods

None.

Examples

The following snippet is taken from the resize-observer-text.html (see source) example.

Note that the code covers three different compatibility cases:

  • Some old browsers may support contentRect but not contentBoxSize.
  • Old versions of Firefox support contentBoxSize, but incorrectly implemented it as a single object rather than an array.
  • Modern browsers support contentBoxSize as an array of objects, to enable them to report box sizes for fragmented elements (for example, in a multi-column scenario).
js
const resizeObserver = new ResizeObserver((entries) => {
  for (const entry of entries) {
    if (entry.contentBoxSize) {
      // The standard makes contentBoxSize an array...
      if (entry.contentBoxSize[0]) {
        h1Elem.style.fontSize = `${Math.max(1.5, entry.contentBoxSize[0].inlineSize / 200)}rem`;
        pElem.style.fontSize = `${Math.max(1, entry.contentBoxSize[0].inlineSize / 600)}rem`;
      } else {
        // … but old versions of Firefox treat it as a single item
        h1Elem.style.fontSize = `${Math.max(1.5, entry.contentBoxSize.inlineSize / 200)}rem`;
        pElem.style.fontSize = `${Math.max(1, entry.contentBoxSize.inlineSize / 600)}rem`;
      }
    } else {
      h1Elem.style.fontSize = `${Math.max(1.5, entry.contentRect.width / 200)}rem`;
      pElem.style.fontSize = `${Math.max(1, entry.contentRect.width / 600)}rem`;
    }
  }
  console.log("Size changed");
});

resizeObserver.observe(divElem);

Specifications

Specification
Resize Observer
# resize-observer-entry-interface

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
ResizeObserverEntry
Chrome – Full support
Chrome 64 (Release date: 2018-01-23)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 69 (Release date: 2019-09-03)
footnote Full support
Opera – Full support
Opera 51 (Release date: 2018-02-07)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 64 (Release date: 2018-01-23)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 64 (Release date: 2018-01-23)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
borderBoxSize
Chrome – Full support
Chrome 84 (Release date: 2020-07-27)
footnote Full support
Edge – Full support
Edge 84 (Release date: 2020-07-16)
footnote Full support
Firefox – Partial support
Firefox 69 – 91 (Release date: 2019-09-03)
footnote Partial support
footnote Implemented as a single object representing a content box size, rather than an array of content box size objects.
Firefox – Full support
Firefox 92 (Release date: 2021-09-07)
footnote Full support
Opera – Full support
Opera 70 (Release date: 2020-07-27)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 84 (Release date: 2020-07-27)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 79 – 91 (Release date: 2020-07-28)
footnote Partial support
footnote Implemented as a single object representing a content box size, rather than an array of content box size objects.
Firefox for Android – Full support
Firefox for Android 92 (Release date: 2021-09-07)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 84 (Release date: 2020-07-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
contentBoxSize
Chrome – Full support
Chrome 84 (Release date: 2020-07-27)
footnote Full support
Edge – Full support
Edge 84 (Release date: 2020-07-16)
footnote Full support
Firefox – Partial support
Firefox 69 – 91 (Release date: 2019-09-03)
footnote Partial support
footnote Implemented as a single object representing a content box size, rather than an array of content box size objects.
Firefox – Full support
Firefox 92 (Release date: 2021-09-07)
footnote Full support
Opera – Full support
Opera 70 (Release date: 2020-07-27)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 84 (Release date: 2020-07-27)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 79 – 91 (Release date: 2020-07-28)
footnote Partial support
footnote Implemented as a single object representing a content box size, rather than an array of content box size objects.
Firefox for Android – Full support
Firefox for Android 92 (Release date: 2021-09-07)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 84 (Release date: 2020-07-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
contentRect
Chrome – Full support
Chrome 64 (Release date: 2018-01-23)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 69 (Release date: 2019-09-03)
footnote Full support
Opera – Full support
Opera 51 (Release date: 2018-02-07)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 64 (Release date: 2018-01-23)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 64 (Release date: 2018-01-23)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
devicePixelContentBoxSize
Chrome – Full support
Chrome 84 (Release date: 2020-07-27)
footnote Full support
Edge – Full support
Edge 84 (Release date: 2020-07-16)
footnote Full support
Firefox – Full support
Firefox 93 (Release date: 2021-10-05)
footnote Full support
Opera – Full support
Opera 70 (Release date: 2020-07-27)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 84 (Release date: 2020-07-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 93 (Release date: 2021-10-05)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 84 (Release date: 2020-07-27)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
target
Chrome – Full support
Chrome 64 (Release date: 2018-01-23)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 69 (Release date: 2019-09-03)
footnote Full support
Opera – Full support
Opera 51 (Release date: 2018-02-07)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 64 (Release date: 2018-01-23)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 64 (Release date: 2018-01-23)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Has more compatibility info.