Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The devicePixelContentBoxSize read-only property of the ResizeObserverEntry interface returns an array containing the size in device pixels of the observed element when the callback is run.
An array containing objects with the new size of the observed element in device pixels. The array is necessary to support elements that have multiple fragments, which occur in multi-column scenarios. Each object in the array contains two properties:
blockSizeThe size of the content-box, in device pixels, of the block dimension of the observed element. For boxes with a horizontal writing-mode, this is the vertical dimension, or height; if the writing-mode is vertical, this is the horizontal dimension, or width.
inlineSizeThe size of the content box, in device pixels, of the inline direction of the observed element. For boxes with a horizontal writing-mode, this is the horizontal dimension, or width; if the writing-mode is vertical, this is the vertical dimension, or height.
Note: For more information about writing modes and block and inline dimensions, read Handling different text directions.
The following example is taken from the article Pixel-perfect rendering with devicePixelContentBox. As the callback function of a ResizeObserver is called after layout but before paint. This provides an opportunity to log the exact size in physical pixels to ensure a one-to-one mapping of canvas pixels to physical pixels.
| Resize Observer # dom-resizeobserverentry-devicepixelcontentboxsize |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Dec 19, 2024 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.