Menu

How To Create An Autoscale Text Box In After Effects

Introduction

Hey everyone, this is Owen with Motion Array and in this tutorial I’ll be showing you how to make an auto scaling text box. There’s a handful of tutorials out there that cover this topic in great detail and spend time explaining exactly what the code is doing. This isn’t one of those tutorials, we’re just trying to get you the information you need and back to work. Alright let’s get started.

How To Create An Autoscale Text Box In Adobe After Effects

This text has been transcribed from the video for optimal reading

Project Files Can Be Downloaded HERE

I’ll begin by making a new composition that’s 1920x1080 29.97. Inside the new composition create a new text layer and type “My Text Layer". Go to Layer > New > Shape Layer. Name the new shape layer “Text Box”. Add a rectangle to the Text Box layer and add a fill. Twirl down the properties for the rectangle path and option(alt) + click on the stopwatch for the Size property. In the expression editor we are going to be writing a little bit of code. First, let’s define a variable so that we can easily reference the text layer. Type “s=“ and then use the pick whip to link to the text layer and then add a semicolon(“;”). Hit return to start a new line of code and add the following in. 

w=s.sourceRectAtTime().width;
h=s.sourceRectAtTime().height;

[w,h]

So your full expression should look like this:

s=thisComp.layer("My Text Layer");
w=s.sourceRectAtTime().width;
h=s.sourceRectAtTime().height;

[w,h]

We’re defining two new variables with this code and then using them as the X and Y size values. “sourceRectAtTime()” references the size of the text layer. So now the Text Box will always be the right size, all that’s left is to make sure it’s in the right position. Grab the rectangle near the top left corner and holding command drag it to the top left corner of the text layer (holding command will make it snap). Now access the position of the rectangle path (not the layer!) and apply the following expression:

s=thisComp.layer("My Text Layer");
w=s.sourceRectAtTime().width/2;
h=s.sourceRectAtTime().height/2;
l=s.sourceRectAtTime().left;
t=s.sourceRectAtTime().top;

[w+l,h+t]

You’ll notice this expression is similar to what we used for the size. We’ve added in two new variables though that look at where the top and the left boundaries are of the text layer. These help place the box in the right spot. So now we’ve got all the coding done and we 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 and in most cases you’ll want that. To create some breathing room 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. The great thing about this text box being a shape layer is you can also add a stroke for even more customization. I’ll add a stroke to the Text Box and I think that’s looking pretty good. 

At this point we’re pretty much done but 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 that you adjust the scale and rotation of the text layer and the Text Box will adjust with it. Pretty slick!

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

Well, that concludes this tutorial. I hope you found it helpful, if you did, please give us a thumbs up and if you’d like to see more tutorials please go ahead and subscribe because we’re making new ones all the time.  I hope you guys found it helpful.  If you did, we’ve got lots of other Premiere Pro tutorialsAfter Effects tutorials and filmmaking tutorials!

Thanks for watching and see you in the next video.

Music Provided By Motion Array:

https://motionarray.com/stock-...

156813 Files & Counting!

9170 files added in the last 30 days!

Join now, and get instant access to all of our files.

View pricing Join Free