When working with text animations in After Effects, manually adjusting background shapes to fit the text can be time-consuming and frustrating. Fortunately, there’s a way to make text boxes automatically resize based on the text content using expressions. This not only saves time but also ensures a dynamic and professional look for your animations.
In this guide, we’ll go step by step on how to create an auto-resizing text box in After Effects using expressions. By the end, you’ll be able to apply this technique to any text animation project with ease.
Step 1: Create a New Composition and Add Text
- Open After Effects and create a new composition.
- Set the dimensions to 1920x1080 and duration to 10 seconds.
- Click the Text Tool (T) and type your desired text.
- Adjust the font, size, and alignment as needed.
- Use the Align Panel to center the text horizontally and vertically.
Step 2: Center the Anchor Point
For a clean and organized animation, ensure the Anchor Point is centered:
- Select the Text Layer.
- Press Ctrl + Alt + Home (Windows) / Cmd + Option + Home (Mac) to center the Anchor Point within the text.
- Use the Align Panel again to recenter the text.
Step 3: Create a Shape Background
- Deselect all layers.
- Select the Rectangle Tool (Q) and draw a shape behind your text.
- Adjust the shape’s fill color and remove any stroke if necessary.
- Move the Shape Layer below the text layer in the timeline.
Step 4: Link the Shape Size to the Text Automatically
To make the background resize dynamically, we’ll use an expression.
- Expand the Shape Layer properties and go to
Rectangle Path > Size
. - Hold Alt (Windows) / Option (Mac) and click on the stopwatch icon next to Size.
- In the Expression Editor, enter the following code:
s = thisComp.layer("YourTextLayerName");
w = s.sourceRectAtTime().width;
h = s.sourceRectAtTime().height;
[w, h]
- Replace “YourTextLayerName” with the actual name of your text layer.
- Click Enter to apply the expression.
Now, whenever you change the text content, the background automatically resizes to fit!
Step 5: Adjust the Padding
By default, the background may be too tight around the text. To add some padding:
- Expand the Shape Layer properties.
- Click Add > Offset Paths.
- Increase the Offset value to add padding.
Step 6: Round the Corners (Optional)
For a softer look, you can round the corners of your shape:
- Under Offset Paths, locate the Line Join option.
- Set it to Round Join.
Step 7: Animate the Text and Background
Now that our text box resizes dynamically, let’s animate it.
Fade-In Effect
- Select the Text Layer.
- Press T to open the Opacity property.
- Set a keyframe at 0% opacity at the start of the timeline.
- Move a few frames forward and set it to 100%.
Slide-In Animation
- Select both the Text Layer and Shape Layer.
- Press P to open the Position property.
- Move to frame 0, create a keyframe with the text off-screen.
- Move forward in time and bring the text to its final position.
Step 8: Use It in Multiple Lines
For multi-line text, the method changes slightly.
- Pre-compose the Text and Shape Layer by selecting both and pressing Ctrl + Shift + C (Windows) / Cmd + Shift + C (Mac).
- Duplicate the pre-comp and update the text inside without affecting other instances.
By using this auto-resizing text box method, you can make your After Effects projects more efficient and professional. Whether you're creating lower-thirds, title screens, or social media animations, this technique will save you time and effort.
Comments (0)
Sign in to comment
Report