IT lexicon › Web › Resize Observer

Resize Observer

Web På svenska → Updated: 2026-05-30

A web API that notifies when a specific element's size changes — not just the whole window. It solves the problem of reacting to a single container changing dimensions, regardless of why (window change, layout change, content).

The old problem: the window.resize event only says that the WINDOW changed, not whether a single element changed size because of something else (a sidebar folding out, content growing, a flex redistribution). Polling the element's size was expensive and choppy. Resize Observer calls your callback exactly when the watched element's size changes, with the new dimensions — efficiently and without layout thrashing. Use case: redraw a canvas/chart when its container changes, JS-based "container query" solutions (before CSS container queries existed), adapt a component to its own width. Win: precise, element-specific size monitoring. One of the observer trio (Intersection, Resize, Mutation). It's now complemented by CSS container queries for pure styling needs, but Resize Observer is needed when JS must react to dimensions. Related to intersection observer and container queries.

← Back to the lexicon