JSFiddle - React, Tailwind, and code Playground

HTML

<div id="Div1">2116970</div>

CSS

#Div1 { width: 150px; }

JavaScript

window.onload = function() {
    var oDiv = document.getElementById("Div1");
    oDiv.style.overflow = "auto";
    var fontSize = 14;
    var changes = 0;
    var blnSuccess = true;
    while (oDiv.scrollWidth <= oDiv.clientWidth) {
        oDiv.style.fontSize = fontSize + "px";
        fontSize++;
        changes++;
        if (changes > 500) {
            blnSuccess = false;
            break;
        }
    }
    if (changes > 0) {
        //upon failure, revert to original font size:
        if (blnSuccess)
            fontSize -= 2;
        else
            fontSize -= changes;
        oDiv.style.fontSize = fontSize + "px";
    }
};