Is it possible to dynamically scale text size based on browser width?

Hell yeah!

Set your <body> font size when the window is resized with a little javascript. (I’ve used jQuery for convenience here:

$( document ).ready( function() {
            var $body = $('body'); //Cache this for performance

            var setBodyScale = function() {
                var scaleSource = $body.width(),
                    scaleFactor = 0.35,                     
                    maxScale = 600,
                    minScale = 30; //Tweak these values to taste

                var fontSize = scaleSource * scaleFactor; //Multiply the width of the body by the scaling factor:

                if (fontSize > maxScale) fontSize = maxScale;
                if (fontSize < minScale) fontSize = minScale; //Enforce the minimum and maximums

                $('body').css('font-size', fontSize + '%');
            }

            $(window).resize(function(){
                setBodyScale();
            });

            //Fire it when the page first loads:
            setBodyScale();
        });

Because your font size is set in em’s (perfect) adjusting the percentage font-size of the body element acts as a universal ‘text zoom’. This will scale any text set in em’s – if you want to be more specific, you could set the percentage font-size on a <div> that surrounds just the elements you want to scale.

Here’s a quick example: http://www.spookandpuff.com/examples/dynamicTextSize.html

Leave a Comment