Testing

devicePixelRatio: Browser Support, Use Cases, Limits

window.devicePixelRatio works in Chrome 4+, Edge 12+, Firefox 18+, Safari 3.1+, Opera 11.6+, IE 11, and Samsung Internet 4+. See browser support and uses.

Author

Prince Dewani

May 1, 2026

window.devicePixelRatio is a read-only JavaScript property defined in the W3C CSSOM View Module that returns the ratio of physical pixels to CSS pixels for the current display. It works in Chrome 4+, Edge 12+, Firefox 18+, Safari 3.1+ on macOS, Safari 3.2+ on iOS, Opera 11.6+, IE 11, Samsung Internet 4+, and Android Browser 2.1+.

This guide covers what devicePixelRatio is, the browsers that support it, how to use it, the production use cases, and the known limitations.

What is devicePixelRatio?

window.devicePixelRatio is a read-only property on the Window interface that returns a Number equal to the ratio of physical pixels to CSS pixels on the current display. The W3C CSSOM View Module defines it. A standard 96-DPI monitor returns 1, a Retina display returns 2, and modern flagship phones return 3 or higher.

Which browsers does devicePixelRatio support?

Every modern desktop and mobile browser supports window.devicePixelRatio, with global coverage near 97%. Internet Explorer 11 is the only IE version with support, and a few legacy mobile builds report quirky values on Retina displays.

Loading browser compatibility data...

devicePixelRatio compatibility in Chrome

Chrome supports window.devicePixelRatio from Chrome 4 on Windows, macOS, Linux, ChromeOS, and Android. Chrome 1 to 3 did not expose the property. The value tracks both the display's physical density and the page zoom level, so a 200% zoom on a 96-DPI monitor returns 2 in Chrome.

devicePixelRatio compatibility in Edge

Microsoft Edge supports window.devicePixelRatio from Edge 12 on Windows. The legacy EdgeHTML versions (Edge 12 to 18) read the same value the OS exposes, including fractional ratios like 1.25 and 1.5 from Windows display scaling. The Chromium-based Edge from Edge 79 on inherits the property on Windows, macOS, Linux, Android, and iOS through the Blink engine.

devicePixelRatio compatibility in Firefox

Firefox supports window.devicePixelRatio from Firefox 18 on desktop and on Firefox for Android. Firefox 2 to 17 did not expose the property and the read returned undefined. The value also reflects the page zoom level in Firefox, so the property is not a pure measure of the panel's physical pixel density.

devicePixelRatio compatibility in Safari

Safari supports window.devicePixelRatio from Safari 3.1 on macOS and from Safari 3.2 on iOS, iPadOS, and iPod touch. Retina MacBooks return 2, the iPhone Plus and Pro Max series return 3 on the inner CSS grid, and standard non-Retina iMacs return 1. Pinch-zoom on iOS does not change the value.

devicePixelRatio compatibility in Opera

Opera supports window.devicePixelRatio from Opera 11.6 on Windows, macOS, and Linux through the Presto engine, and from Opera 15 on through the Chromium base. Opera 9 to 11.5 did not support it. Opera Mobile shipped support from Opera Mobile 12, and Opera Mini exposes the property since the proxy renderer reports a fixed ratio of 1.

devicePixelRatio compatibility in Samsung Internet

Samsung Internet supports window.devicePixelRatio from Samsung Internet 4 on Galaxy phones and tablets. The browser reads the value through the same Blink pipeline as Chrome on Android, so a Galaxy S-series flagship typically returns 3 or higher and a Galaxy A-series mid-range device returns 2 or 2.625.

devicePixelRatio compatibility in Android Browser

The legacy stock Android Browser supports window.devicePixelRatio from Android 2.1 onwards, frozen at version 4.4 before Chrome for Android took over. The value follows Android's density buckets, so a hdpi device returns 1.5, an xhdpi device returns 2, and an xxhdpi device returns 3.

devicePixelRatio compatibility in Internet Explorer

Internet Explorer 11 supports window.devicePixelRatio on Windows 7, Windows 8.1, and Windows 10. IE 5.5 through IE 10 do not expose the property and any read returns undefined. Microsoft has retired Internet Explorer, so use Edge, Chrome, or Firefox on Windows.

Note

Note: window.devicePixelRatio reports different values across Retina Macs, Windows display scaling, and Android density buckets. Test it on real browsers and OS with TestMu AI. Try TestMu AI free!

How do you use window.devicePixelRatio?

Read window.devicePixelRatio in any modern browser to get the physical-to-CSS pixel ratio, then size your canvas, WebGL buffer, or image asset against that number for a sharp render on HiDPI screens.

  • Open the DevTools console: Press F12 or right-click and choose Inspect, then switch to the Console tab in any supported browser.
  • Read the property: Type window.devicePixelRatio and press Enter. The returned Number is the ratio of physical pixels to CSS pixels for the current display.
  • Add a fallback for unknown values: Use window.devicePixelRatio || 1 so legacy or proxy browsers default to a 1:1 ratio if the property is undefined.
  • Scale a canvas backing store: Multiply canvas.width and canvas.height by the ratio, then call ctx.scale(dpr, dpr) so one CSS pixel maps to one physical pixel on Retina displays.
  • Listen for ratio changes: Use window.matchMedia with a resolution query and watch the change event so the page redraws when the user zooms or moves the window between monitors.
const dpr = window.devicePixelRatio || 1;
console.log(`Device pixel ratio: ${dpr}`);

const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");

const cssWidth = canvas.clientWidth;
const cssHeight = canvas.clientHeight;

canvas.width = cssWidth * dpr;
canvas.height = cssHeight * dpr;
ctx.scale(dpr, dpr);

const dprQuery = window.matchMedia(`(resolution: ${dpr}dppx)`);
dprQuery.addEventListener("change", () => {
    console.log(`devicePixelRatio changed to ${window.devicePixelRatio}`);
});

If the snippet logs 1 on a phone or Retina laptop you expect to be HiDPI, the page is likely running inside an embedded WebView with display scaling forced off, or in a proxy browser like Opera Mini that reports a fixed 1.

What are the use cases of devicePixelRatio?

Anything that draws bitmap-style content reads window.devicePixelRatio to pick the right pixel budget, from canvas and WebGL apps to charting libraries and responsive image pipelines.

  • Sharp canvas drawing: Match the canvas backing store to the device pixel grid so lines, text, and gradients render crisply on Retina laptops and HiDPI phones instead of looking blurred.
  • WebGL render buffer sizing: Multiply the drawingBufferWidth and drawingBufferHeight by the ratio so a WebGL scene renders at native resolution on HiDPI screens without aliasing.
  • Responsive image selection: Pair the ratio with the srcset and sizes attributes, or read it directly to decide between a 1x, 2x, or 3x asset for hero images and product photos.
  • Charting libraries: Chart.js, D3, and ECharts read window.devicePixelRatio to upscale the canvas backing store, which is why a Chart.js bar chart looks sharp on a MacBook Retina display.
  • Pixel-perfect overlays: Annotation tools, image editors, and PDF viewers align hairline strokes and 1-pixel borders to the physical grid so they do not blur or disappear on HiDPI screens.
  • Adaptive video resolution: Players can request a 1080p stream on a 1x display and a 4K stream on a 3x phone, saving bandwidth where extra pixels would not be visible.
...

What are the limitations of devicePixelRatio?

window.devicePixelRatio is a useful hint, but the value mixes display density, page zoom, and OS scaling into a single number, which makes it tricky to interpret in isolation.

  • Browser zoom shifts the value: Chrome, Firefox, and Edge fold the page zoom level into the ratio, so a 200% zoom on a 96-DPI monitor reports 2 even though the panel itself is 1x.
  • Fractional values on Windows: Windows display scaling at 125% or 150% surfaces as 1.25 or 1.5, and ChromeOS reports similar floats on tablet-class hardware. Round carefully when sizing pixel-aligned canvases.
  • No native change event: The property does not fire its own event when the value changes. Use window.matchMedia with a resolution query to detect zoom shifts or monitor changes.
  • Per-monitor differences: A laptop docked to an external 4K monitor and the built-in Retina screen often expose different ratios. Reading the value once at startup misses the change when the window moves between screens.
  • Fingerprinting signal: The exact float adds entropy to a browser fingerprint. Tor Browser and Brave Shields can spoof the value to 1 or round it to the nearest integer to limit cross-site tracking.
  • Opera Mini and proxy browsers: Server-rendered proxy browsers report a fixed ratio of 1 regardless of the real device, so HiDPI assets never load on Opera Mini even on a Retina-class phone.

In my experience, the bigger trap is treating window.devicePixelRatio as a static integer: a Windows laptop docked to a 1x external monitor reports 1, the same machine undocked at 150% reports 1.5, and zooming to 200% reports 3, all in the same session. Always feature-detect, round defensively, and listen for resolution changes through matchMedia.

...

Citations

All window.devicePixelRatio version numbers and platform notes in this guide come from these primary sources:

Author

Prince Dewani is a Community Contributor at TestMu AI, where he manages content strategies around software testing, QA, and test automation. He is certified in Selenium, Cypress, Playwright, Appium, Automation Testing, and KaneAI. Prince has also presented academic research at the international conference PBCON-01. He further specializes in on-page SEO, bridging marketing with core testing technologies. On LinkedIn, he is followed by 4,300+ QA engineers, developers, DevOps experts, tech leaders, and AI-focused practitioners in the global testing community.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

Frequently asked questions

Did you find this page helpful?

More Related Hubs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests