Explore element resize observation, breakpoint detection, and responsive component patterns
Drag the corner of the box below to resize it. The observer reports contentBoxSize, borderBoxSize, and devicePixelContentBoxSize.
ResizeObserver enables element-level breakpoints. Drag to resize the container and watch the breakpoint change. This is the core pattern behind CSS Container Queries, implemented in JavaScript.
A card that switches between horizontal and vertical layout based on its own width. Drag the right edge to resize.
This card adapts its layout based on its own width, not the viewport.
Toggle observation on individual elements. When unobserved, resizing generates no callbacks.
A common pitfall: resizing an observed element inside its own callback creates an infinite loop. The browser detects this and delivers a single "error" event. Here we demonstrate safe vs unsafe patterns.
A single ResizeObserver can watch multiple elements. Add elements dynamically and observe them all.