← All Articles
Tutorial

How to Vertically Align Text in After Effects Using Expressions

How to Vertically Align Text in After Effects Using Expressions

If you've been making subtitles in After Effects like me, you probably found out that sometimes you need the text layer to be aligned vertically. This is not an issue if you only have one line of text. But as soon as you have two lines or more, you have to adjust the position to align it again.

I've had my fair share of manually fixing this until I discovered a simple expression that works like magic. Whatever you type, the text will always be vertically aligned.

Setting Up the Text Box

To get the best results, you should create a text box instead of just a text. You do this by selecting the text tool and instead of just clicking on the composition, you're gonna click and drag to create a box. When you give the text box a specific width, your text will have line breaks automatically once it reaches the edge. This makes the work easier.

The Expression

Type whatever you want inside your textbox, and open the layer properties until you see the Anchor Point. You can also select the layer and just press "A" to see it.

We need to add an expression in the **Anchor Point** property by pressing ALT and clicking on the stopwatch icon. This will open a small code editor where we need to type the following:

a=sourceRectAtTime();
[0,a.top+a.height/2]+value

The anchor point of the layer will adjust itself depending on the height of the text, not the textbox, with the ability to change it manually if needed thanks to the "value" parameter.

When to use this

- Subtitle templates with varying text lengths - Lower thirds that need consistent vertical positioning - Any text that changes dynamically and needs to stay centered

And that should do it!

Check out my free tools

Built for motion designers - render calculators, timecode converters, and more.

View Tools

Let's talk

Available for product videos, animation systems, creative direction, and workshops.