JSFiddle - React, Tailwind, and code Playground
HTML
<div class="test">
Blablabla
</div>
<div class="test" id="fit">
<span id="wrap">Blablabla12124e121211asdasasas</span>
</div>
CSS
.test {
width: 200px;
border: 1px solid black;
font-size: 16px;
}
JavaScript
var fit = document.getElementById("fit"),
wrap = document.getElementById("wrap"),
step = 0.5,
currentSize;
while (fit.offsetWidth < wrap.offsetWidth) {
currentSize = parseFloat(window.getComputedStyle(wrap, null).getPropertyValue('font-size'));
wrap.style.fontSize = (currentSize - step) + "px";
}