How to Create an Autoscale Text Box in After Effects

After Effects 19/11/2018 3 min read

An autoscaling text box is an incredible time-saving tool that isn’t yet built into After Effects, but can be created yourself with the help of expressions. The tutorial below won’t run through exactly what every bit of code is, but it will get you the information you need to get the job done. Let’s jump into how to autoscale text in After Effects CC.

How to Make an Autoscale Text Box

Step 1: Create a Text Box

  1. Create a new composition at 1920×1080 29.97
  2. Inside this composition, create a new Text layer, and type in whatever you want. 
  3. Go to Layer > New > Shape Layer. Name the new shape layer “Text Box.” 
  4. Add a Rectangle to the Text Box layer, and add a Fill
  5. Twirl down the properties for the Rectangle path and Option (ALT) + click on the Stopwatch for the Size property. 

Step 2: Create an Expression to Autoscale the Text Box

  1. Before you write any code in the Expression Editor, define a variable to easily reference the text layer. Type “s=“, and use the pick whip to link to the Text layer, then add a semicolon(“;”)
  2. Hit return to start a new line of code, and add in the following:


Your full expression should look like this:

s=thisComp.layer(“My Text Layer”);

This code defines two new variables, and then uses them as the X and Y size values. “sourceRectAtTime()” references the size of the text layer. 

Step 3: Reposition the Text Box 

Now the text box will always be the right size, all that’s left is to make sure it’s in the right position. 

  1. Grab the Rectangle near the top left corner. Holding Command, drag it to the top left corner of the Text layer. Holding Command will make it snap. 
  2. Now access the Position of the rectangle path (not the layer!), and apply the following expression:

s=thisComp.layer(“My Text Layer”);

You’ll notice this expression is similar to what you used for the size. 

The difference is two new variables that look at where the top and the left boundaries of the text layer are. These help place the box in the right spot. 

Step 4: Add Padding Between the Box and the Text

So now the coding is done, and you have a box that is the same size as the text. The problem is that it’s only as big as the text, so there’s no padding. In most cases, you’ll want that. To create some breathing room: 

  1. Add an Offset Paths to the Text Box layer from the shape layer menu. By adjusting the Amount in the Offset Paths, you can add or subtract padding. 
  2. The great thing about this text box being a shape layer is you can also add a Stroke for even more customization. Play around with this until you get something you’re pleased with visually.

For added flexibility, it’s a good idea to parent the text box to the text layer. That way, you can move the text layer wherever you need to in the comp, and the text box will follow. 

This also means you can adjust the scale and rotation of the text layer, and the text box will adjust with it. Pretty slick!

There you have it! It’s worth taking some time to learn more about expressions, as they can be applied to plenty of different situations. Learning how to create an autoscale text box in After Effects is an excellent place to start. If you’d like to know more about the nitty-gritty of this expression and customizing it even further, check out this tutorial by Jake In Motion.

Share this article: