---
url: "https://web.dev/articles/device-pixel-content-box"
titulek: "Pixel-perfect rendering with devicePixelContentBox | Articles | web.dev"
h1: "Pixel-perfect rendering with devicePixelContentBox Stay organized with collections Save and categorize content based on your preferences."
popis: "Since Chrome 84, ResizeObserver supports a new box measurement called device-pixel-content-box, that measures the element's dimension in physical pixels. This is crucial for rendering pixel-perfect graphics, especially in the context of high-density screens."
jazyk: "en"
kanonicka: "https://web.dev/articles/device-pixel-content-box"
drobecky: ["Articles", "Pixel-perfect rendering with devicePixelContentBox"]
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-14 01:49:10"
znaku: 10305
slov: 1618
kodovani: "iso-8859-2"
sha256: "11e3ea04800dbeeab335045f445061fae25a29e4950327481fc1e2aed604d8cf"
---
Pixel-perfect rendering with devicePixelContentBox
Stay organized with collections
Save and categorize content based on your preferences.
How many pixels are there *really* in a canvas?
Surma
Since Chrome 84, [ResizeObserver](/resize-observer) supports a new box measurement called `devicePixelContentBox`, that measures the element's dimension in *physical* pixels. This enables rendering pixel-perfect graphics, especially in the context of high-density screens. Browser Support
84
84
108
x
[Source](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize) Background: CSS pixels, canvas pixels, and physical pixels While we often work with abstract units of length like `em`, `%` or `vh`, it all boils down to pixels. Whenever we specify the size or position of an element in CSS, the browser's layout engine will eventually convert that value to pixels (`px`). These are "CSS Pixels", which have a lot of history and only have a loose relationship with the pixels you have on your screen. For a long time, it was fairly reasonable to estimate anyone's screen pixel density with 96DPI ("dots per inch"), meaning any given monitor would have roughly 38 pixels per cm. Over time, monitors grew and/or shrunk or started to have more pixels on the same surface area. Combine that with the fact that lots of content on the web define their dimensions, including font sizes, in `px`, and we end up with illegible text on these high-density ("HiDPI") screens. As a counter-measure, browsers hide the monitor's actual pixel density and instead pretend that the user has a 96 DPI display. The `px` unit in CSS represents the size of one pixel on this *virtual* 96 DPI display, hence the name "CSS Pixel". This unit is only used for measurement and positioning. Before any actual rendering happens, a conversion to physical pixels happens. How do we go from this virtual display to the user's real display? Enter `devicePixelRatio`. This global value tells you how many *physical* pixels you need to form a single CSS pixel. If `devicePixelRatio` (dPR) is `1`, you are working on a monitor with roughly 96DPI. If you have a retina screen, your dPR is probably `2`. On phones it is not uncommon to encounter higher (and weirder) dPR values like `2`, `3` or even `2.65`. It is essential to note that this value is *exact*, but doesn't let you derive the monitor's *actual* DPI value. A dPR of `2` means that 1 CSS pixel will map to *exactly* 2 physical pixels. Example
My monitor has a dPR of `1` according to Chrome⌠It has 3440 pixels in width and the display area is 79cm wide.
That leads to a resolution of 110 DPI. Close to 96, but not quite.
That is also the reason why a `
`
will not exactly measure 1cm in size on most displays. Finally, dPR can also be affected by your browser's zoom feature. If you zoom in, the browser increases the reported dPR, causing everything to render bigger. If you check `devicePixelRatio` in a DevTools Console while zooming, you can see fractional values appear. DevTools showing a variety of fractional `devicePixelRatio` due to zooming. Let's add the `