Auto-scaling text in Adobe After Effects

If you have ever worked with text boxes in programs like Keynote, the auto-scale feature, where the font size automatically scales up or down as you type, helps you focus on the content you’re writing instead of the details of its sizing.

You can do the same thing with text layers in Adobe After Effects with some help from a bit of expression magic. This is especially helpful for maintaining consistency if you are working with multiple compositions that have copy that varies in length.

Image for post
Image for post

Set up your composition and add your text layer. You’ll want to set a baseline font size for things, so enter a bit of text and size it to look the way you want that amount of text to look. This is more of an art than a science, so go with your ❤️ here.

This is where the magic happens. Since you can’t use expressions to modify font sizes directly, you’ll need to adjust the size of your text using the scale property.

If you alt+click the stopwatch for your text layer’s Scale property, the expression text box will appear in the timeline. Paste in the expression below and modify it to suit your needs. If you are feeling spry, you can even map the hardcoded values in your expression to controls in your composition for more flexibility while you find a good fit.

Paste this code in for your text layer’s scale expression

// This lets us get the width of the textbox containing your content.layerWidth = thisLayer.sourceRectAtTime(time).width;
// This lets us get the width of the current composition.compWidth = thisComp.width;
// This lets you specify a maximum width that text boxes should not exceed. In this example it’s 90%, but you can set it to whatever you need or even map it to a control.// Pro-tip: If you have other content in the same horizontal space as your text, remember to account for that content when setting your maximumWidth.maximumWidth = compWidth * .9;
// This calculates the current percentage of the maximum width that the text layer occupies.percentageOfMaxWidth = layerWidth / maximumWidth * 100;
// We subtract that percentage from 100 to find out how much space we can spare. If the text box can grow a bit, leeway is positive. If it needs to shrink, leeway will be negative.leeway = 100 - percentageOfMaxWidth;
// Finally, return an array of [width, height] scale. 100 is the baseline and leeway is how much the layer needs to grow or shrink to fit.[100 + leeway, 100 + leeway]

Try out this expression and let me know how it works for you. Good luck!

Written by

Area dad. Occasional vigilante politician. Anti-corruption. Pro-electoral reform. Fighting for working people.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store