CKTIS / JavaScript
ResizeObserver.observe — observing element size
ResizeObserver.observe registers an element for asynchronous size notifications. The box option selects the observed area.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
observer.observe(target, { box: "content-box" });observer.observe(target, options) accepts an Element and returns undefined. Notifications reach the observer callback during rendering, not synchronously.
box defaults to "content-box" (content); "border-box" also includes padding and borders, while "device-pixel-content-box" measures content in integer device pixels. This selection controls notification triggering, not available entry fields. CSS transforms do not trigger observations.
Calling observe again for the same element with the same box value is a no-op in Chromium. Do not rely on such a call to replace the registration or reset its notification state across browsers. unobserve(target) removes one; disconnect() removes all. Avoid cyclic size changes in the callback. This is a Web API, not an ECMAScript feature; Node 24 does not establish browser support.
Examples
const target = document.createElement("div");
target.style.cssText = "all: initial; display: block; width: 120px; height: 40px;";
document.body.append(target);
const observer = new ResizeObserver(([entry]) => {
console.log(`${entry.contentRect.width} x ${entry.contentRect.height}`);
observer.disconnect();
target.remove();
});
observer.observe(target, { box: "content-box" });Result
120 x 40
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.