You can use this trick in pure JavaScript to "automatically resize" the font size:
window.onload = function() { var oDiv = document.getElementById("Div1"); oDiv.style.overflow = "auto";
Live test .
Start with the actual font size of the <div> if you know it, otherwise it’s better to use a lower number as the first number.
The above code works on the principle that when the text is larger than the specified width of its container, the scrollWidth property, which is the "actual" width, will be larger than the set width.
Edit:. Firefox will not update the scrollWidth property if the CSS overflow property is set to “visible” by default, so you must set it to “auto” - the code does this for you, but it is also possible to set it using CSS if you prefer.
source share