Skip to main content
cb-torpedo
New Member
January 8, 2024
Question

Dynamically reduce text font size or scale to fit parent container?

  • January 8, 2024
  • 21 replies
  • 43164 views
  • I need a single line of text to fit within a container without wrapping, breaking the boundary, or truncating.
  • I need the text to get smaller when it gets too long to fit, either by reducing font size or overall scale.
  • The text is dynamic, so I can’t reliably tell how long it will be to pick an ideal font size.

Things I’ve tried:

  • Standard left and right with top and bottom constraints, but if the text becomes too long, it wraps and breaks the boundary or truncates.
  • Using text auto width with scale constraints, but the text just grows outside the boundary.
  • Using text auto width then wrapping it with an auto layout, thinking the layout could hug the text and use scale constraints to get smaller, but hug resizing and scale constraints are mutually exclusive.

Is there any way to do this dynamically?

21 replies

cb-torpedo
New Member
January 9, 2024

Thanks for your reply, but I can’t seem to follow what you suggested, starting with Step 3…

  1. Constraints seem to be disabled on objects inside an Auto Layout frame. All I have are Resizing Options on the Text Layer. Selecting anything other than Hug changes the text’s Auto Width to something else, contradicting Step 2.

  2. As with Step 3, Constraints are disabled on objects inside an Auto Layout frame, so I can’t apply Scale Constraints. Holding Shift and dragging one of Text Layer’s corners just changes the Resizing Options from Hug to Fixed, which also changes the text’s Auto Width to Fixed Size, again contradicting Step 2.

  3. I’m not seeing any Auto Layout properties on the Text Layer, just the typical Resizing Options I mentioned earlier. I’ve never seen a “Shrink” option in regards to text.

Here’s a screenshot of my Design Panel for the Text Layer:

Can you maybe send some screenshots where these options are?

Thanks again, much appreciated.

Raphael_M
Power Member
January 10, 2024

Hi.

I don’t think you can dynamically scale the font size of a Text element in Figma by changing/scaling the size of it’s parent layer, or maybe not yet, or maybe I am wrong.

What you can do if you want your text to a single line and fits the container without wrapping, breaking the boundary, or truncating the text is by using this technique:

  1. Through Auto-layout - Set the text element to auto-width and the auto-layout container to hug. The container will just adjust it’s width depending on the length of the text layer without wrapping or breaking it but the problem is you won’t be able to adjust it’s width or length manually else the hug properties will be removed and become fixed.

  2. Scale - If you want to manually scale the container where the text will also scale dynamically, you can use the scale tool in Figma. You can find it on the tools menu on the upper left corner of the app.
    image

cb-torpedo
New Member
January 11, 2024

Thanks Raphael14, appreciate your time.

I am familiar with that setup, where the text drives the parent container size, but in this case I was hoping to reverse that relationship, and have the parent container drive the text size. Can’t seem to figure out a way to do that.

Thanks though!

stammeredads
New Participant
January 11, 2024

Consider using an UILabel with adjustsFontSizeToFitWidth set to true, and add constraints for left, right, top, and bottom. Combine this with a minimum font scale and ensure the content hugging priority is lower than the compression resistance priority. This allows dynamic text adjustment within the container without wrapping or breaking boundaries.

cb-torpedo
New Member
January 16, 2024

Those look like Swift commands. I don’t see how to use them in Figma.

Am I missing something? Can you show me how to apply this to a Figma design?

team2
April 17, 2024

i think people are using chatgpt to answer your question- the answers even ‘sound’ like gpt’s phrasing. ultimately not helpful cuz gpt is known to make stuff up when you ask it for help on specific products. question is why are they doing this? do we get brownie points for solving community issues?

Raphael_M
Power Member
April 18, 2024

At first, I’m thinking being formal is good. And then if I think about it, having more understanding on the technical terms will make you sound like a robot (and also because I’m using the same sentence structure).

Why are we doing this? do we get brownie points for solving community issues?

Not at all. We try to help them as much as we could because we started from the same starting point, and having no one to help you on your questions might make you give up on it. It is not hard to answer some questions anyway, so why not help?

I don’t know why you’re here maybe you have questions unanswered, and is seeking for help, or maybe you have plenty of free time and is looking for news and updates (normally, that’s what I do when im in here).

Evin
New Member
June 17, 2024

I believe so. Extremely unhelpful disinformation. Figma cannot and is not capable of scaling text in the way CSS does. It does not support em / % / vw etc.

June 24, 2024

Scale tool is the best tipp I found on the whole web. it solves all my problems.

Vizulefllry
October 21, 2024

team2 was clearly referring to stammeredads’ comment that is obviously Swift and has nothing to do with Figma.
However, your original answer did not answer the actual question of how to make text smaller, it answered the question of how to make the text container smaller, which on StackOverflow would have been downvoted for not answering the actual question.