devicePixelRatio

definition

window.devicePixelRatio is the ratio between physical pixels and device-independent pixels (dips) on the device.
window.devicePixelRatio = physical pixels / dips

Dips are the abstract pixels that are used to feed information to the width/height media queries and the meta viewport device-width.

relation with other properties

dips:
设置页面的<meta name="viewport" content="width=device-width">
获取document.documentElement.clientWidth,大部分浏览器会返回viewport layout的宽度,即为dips

summary

  • devicePixelRatio is mostly trustworthy on most browsers.
  • On iOS devices, multiply devicePixelRatio by screen.width to get the physical pixel count.
  • On Android and Windows Phone devices, divide screen.width by devicePixelRatio to get the dips count.