CSS resolution detection in JavaScript
npm install res --save
- Get resolution in dpi
- @return number
- Get resolution in dpcm
- @return number
- Get resolution in dppx
- @return number
var res = require('res')
res.dppx() // 1
res.dpi() // 96
res.dpcm() // 37.79527559055118
- dppx equals
devicePixelRatio
- dppx is the preferred resolution unit for web design
- User zoom affects resolution
res was mainly written for investigative purposes. Making retina design accommodations can be impractical. Consider alternatives to resolution detection.
Device | res.ddpx() |
res.dpi() |
res.dpcm() |
---|---|---|---|
desktop at default zoom | 1 | 96 | 37.79527559055118 |
iPhone 4s at default zoom | 2 | 192 | 75.59055118110236 |
- Webkit (Chrome/Safari/Android)
- Firefox 18+
- Opera 11.1+ (Presto 2.8+)
- IE 6+
Methods return 0
where undetectable.
MIT