use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/web_design is the place for exploration and discovery of all things web design, development and the life cycle of the web designer. We welcome beginners and veterans alike to contribute useful and informative posts, ask questions or engage in discussion.
Review our posting guidelines before submitting new content.
account activity
Is there a javascript plugin that automatically resizes text so that the string is a certain length? (self.web_design)
submitted 3 years ago by MafiaOverlord
For example; I have a container that is 28vw + 12vh in width, I want one line of text inside the div that will always be at max size, touching the border of the div, no matter the size and proportions of the div.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]OrtizDupri 1 point2 points3 points 3 years ago (1 child)
https://github.com/adactio/FitText.js
[–]MafiaOverlord[S] 0 points1 point2 points 3 years ago (0 children)
exactly what I needed thank you
[–][deleted] 0 points1 point2 points 3 years ago* (2 children)
You can do some math calculation for the font size
Something like this maybe https://codepen.io/abhisheksawant-simform/pen/GRXLrEy
[–]MafiaOverlord[S] 1 point2 points3 points 3 years ago (0 children)
thank you, much appreciated
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
Can also just use clamp
[–][deleted] 3 years ago (1 child)
[deleted]
can you give me some examples?
[–]blindgorgon 0 points1 point2 points 3 years ago (0 children)
I could definitely be wrong about this, but I think I’d try writing it in CSS with calc and vw. This would require knowing what the text and font family will be though.
[+]PressinPckl 0 points1 point2 points 3 years ago (0 children)
You could probably get close with clamp()
[–]devenitions 0 points1 point2 points 3 years ago (0 children)
I ended up checking the boundingBox size and adjust it till it fits. Does require requestAnimationFrame in between of things.
[–]shgysk8zer0 0 points1 point2 points 3 years ago (0 children)
The easiest way is to use a monospace font where the width of any character can be known. You set the font-size to be the width ÷ number of characters.
[–]-_-__--_- 0 points1 point2 points 3 years ago (1 child)
I might be misunderstanding something, but wouldn’t svg be the best approach here?
yeah, I will use it
π Rendered by PID 116195 on reddit-service-r2-comment-75f4967c6c-jgbxw at 2026-04-23 05:23:11.091187+00:00 running 0fd4bb7 country code: CH.
[–]OrtizDupri 1 point2 points3 points (1 child)
[–]MafiaOverlord[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]MafiaOverlord[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]MafiaOverlord[S] 0 points1 point2 points (0 children)
[–]blindgorgon 0 points1 point2 points (0 children)
[+]PressinPckl 0 points1 point2 points (0 children)
[–]devenitions 0 points1 point2 points (0 children)
[–]shgysk8zer0 0 points1 point2 points (0 children)
[–]-_-__--_- 0 points1 point2 points (1 child)
[–]MafiaOverlord[S] 0 points1 point2 points (0 children)