CKTIS / JavaScript
ResizeObserverEntry — the observed element and its size
ResizeObserverEntry describes one element in a ResizeObserver notification. Its target property identifies the element, while contentRect provides its dimensions. Learn the distinction between an HTML content box and an SVG bounding box.
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
new ResizeObserver((entries) => {
for (const entry of entries) {
const element = entry.target;
const { width, height } = entry.contentRect;
}
}).observe(element);ResizeObserverEntry is a record supplied in the entries array to a ResizeObserver callback. One invocation can deliver records for several observed elements, so process the array rather than assuming it contains only one result.
ResizeObserverEntry.target is a read-only property referencing the observed Element or SVGElement. It associates a measurement with the correct element. The reference itself is read-only, but the referenced element can still be modified.
ResizeObserverEntry.contentRect is a read-only property returning a DOMRectReadOnly. For an HTML element, it describes the content box, excluding padding and borders. For an SVG graphics element without an associated CSS layout box, it describes the element's bounding box. An outer <svg> element with a CSS layout box can instead report its CSS content box. Its width and height are dimensions, not the HTML element's outer size. This is a legacy property retained for compatibility; newer properties such as contentBoxSize and borderBoxSize have separate support requirements.
This is a Web API interface, not a feature of a particular ECMAScript edition. MDN marks basic support as widely available since July 2020; additional properties can have different availability. Node 24 does not establish browser support. Notifications are asynchronous. Avoid size changes in the callback that endlessly trigger further notifications.
Examples
(() => {
if (typeof ResizeObserver === "undefined") {
throw new Error("ResizeObserver is not supported");
}
const box = document.createElement("div");
box.id = "resize-demo";
box.style.cssText = "display: block; box-sizing: content-box; width: 120px; height: 60px; padding: 10px; border: 2px solid black;";
document.body.append(box);
const observer = new ResizeObserver((entries) => {
for (const entry of entries) {
const { width, height } = entry.contentRect;
console.log(`${entry.target.id}: ${width} x ${height}`);
}
observer.disconnect();
box.remove();
});
observer.observe(box);
})();Result
resize-demo: 120 x 60
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.