You can try an iterative approach using javascript.
Put content in a range with white-space: nowrap . If span is an interval inside, you can do something like this:
var maxWidth = span.parentNode.clientWidth; var currentFont = parseInt(window.getComputedStyle(span).fontSize);
This will constantly reduce the font until the range is placed in its parent element.
If the selected width changes when the window is resized, you may need to run this when the window is resized.
source share