Pixels vs. Ems: Users DO Change Font Size

The Data

| Size    | Percent of Users |
| ------- | ---------------- |
| 16px | 96.92% |
| 20px | 0.50% |
| 19.2px | 0.42% |
| 25.6px | 0.23% |
| 17px | 0.18% |
| 24px | 0.15% |
| 20.8px | 0.15% |
| 14.4px | 0.10% |
| 18px | 0.10% |
| 18.4px | 0.08% |
| 18.56px | 0.07% |
| 14px | 0.07% |
| Browser                     | Percent of Users |
| --------------------------- | ---------------- |
| Chrome (desktop) | 37.81% |
| Android Webview | 12.89% |
| Opera Mini | 10.88% |
| Firefox (desktop) | 9.17% |
| Samsung Internet | 5.56% |
| Internet Explorer (desktop) | 5.26% |
| Chrome (mobile) | 5.16% |
| Android Browser | 4.35% |
| Safari (desktop) | 3.26% |
| UC Browser | 2.35% |
| Opera (desktop) | 1.07% |
| Internet Explorer (mobile) | 0.32% |
| Safari (mobile/tablet) | 0.29% |

The Code

const original = window.getComputedStyle(document.documentElement).fontSize;
const number = parseFloat(original, 10);
const unit = original.replace(/(\d*.\d+)|\d+/, '');
const defaultFontSize = (number * 1.6) + unit;
const div = document.createElement('div');
div.style.fontSize = 'medium';
document.body.appendChild(div);
const defaultFontSize = window.getComputedStyle(div).fontSize;
document.body.removeChild(div);
function setDefaultFontSizeCustomDimension() {
// Ignore very old browsers.
if (!('getComputedStyle' in window)) {
return;
}
// Get the <html> font size.
const original = window.getComputedStyle(document.documentElement).fontSize;
// Undo the 62.5% size applied in the Bootstrap CSS.
const numPixels = parseFloat(original, 10);
const unit = original.replace(/(\d*\.\d+)|\d+/, '');
const defaultFontSize = (numPixels * 1.6) + unit;
// Our Analytics integration is a little different, but here’s the standard style for reference.
ga('set', 'dimension1', defaultFontSize);
}

The Takeaway

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store