JSFiddle - React, Tailwind, and code Playground

by charlescarver

HTML

<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />

JavaScript

function getPPI(){
 // create an empty element
 var div = document.createElement("div");
 // give it an absolute size of one inch
 div.style.width="1in";
 // append it to the body
 var body = document.getElementsByTagName("body")[0];
 body.appendChild(div);
 // read the computed width
 var ppi = document.defaultView.getComputedStyle(div, null).getPropertyValue('width');
 // remove it again
 body.removeChild(div);
 // and return the value
 return parseFloat(ppi);
}

alert(getPPI());