From my perspective, the range of perceived pixel densities experienced by a website visitor is exceptionally broad. It can vary from viewing content on an HTC One device held 12 inches away with 5600 pixels per radians to watching it on a 50-inch plasma screen running at 480p resolution, which equates to about 950 pixels per radians at a distance of 4 feet.
To put it differently, a 20px font appears nearly six times larger in your field of vision on the plasma screen compared to the latest handset.
The solution I devised involves setting the body font size in absolute pixels as a multiple of the window.screenWidth but limiting it within a specific range. Subsequently, I utilize em's for all font sizes thereafter. By employing em's and using headings appropriately, accessibility should not be an issue.
I implemented this function on the page (or its JavaScript) to adjust the size:
function setFontSize() {
pagesized = window.innerWidth / 30; // Adjust font size proportionately to page
pagesized = Math.max(pagesized, 14); // Ensure size is no less than 14 px
pagesized = Math.min(pagesized, 30); // & Limit to maximum of 30 px
document.body.style.fontSize = pagesized; // Set default body font size
}
To make this functional, the following code is added to the body tag:
<body onresize="setFontSize()" onload="setFontSize()">
Subsequently, you can structure your CSS (or inline styling) based on % or em units, ensuring that everything scales smoothly within these boundaries.
Alternatively, with JQuery, you could use this code:
$(window).resize(function() {
pagesized = $(window).innerWidth() / 30; // Adjust font size proportionally to page
pagesized = Math.max(pagesized, 14); // Ensure size is no less than 14 px
pagesized = Math.min(pagesized, 30); // & Limit to maximum of 30 px
$('body').css('font-size', pagesized); // Set default body font size
});