


Container with fixed height and fixed widthįor this use case we simply have to check, whether the text-wrapping element (a ) overflows on the height and while not, simple increase font-size by 1px.Įnter fullscreen mode Exit fullscreen mode The following sections will use the same simple HTML example for all the use cases, which differ mostly by different CSS.

Container with fixed width and auto height.Container with fixed height and fixed width.It's good to have an online editor, like jsFiddle or CodePen open to follow the seteps interactively. If you feel overwhelmed or found that I used shortcuts that I did not explain well enough, then please leave a comment so this can be improved. There were four use cases I encountered and I'd like to show a potential implementation with additional explanation for each of them. It turned out to be easier than I supposed. I therefore thought of saving the time and hassle of integration and just took on the issue on my own. Well, here is the thing: I tried a few and none really integrated flawlessly into my code. To reflect the "popularity" of this issue just take a look at these StackOverflow questions, asking for nearly the same outcome:įortunately, there are already some resources and tools out there to do the heavy lifting for you: *cover image: Amador Loureiro on UnsplashĪutomatically resizing a text to its parent container can be a big struggle and it becomes nearly impossible if you aim to use CSS only.
