Auto Center Text Anchor Point
- Author:
- Denis Stefanides
- Category:
- Text
Expression Code
// Get the size of the text layer's bounding box
s = sourceRectAtTime(time, false);
// Calculate the center of that box
anchor = [s.left + s.width / 2, s.top + s.height / 2];
// Return the centered anchor point
anchorWhere to Apply
Apply this to the Anchor Point property of any text layer.
It works best when the text is not parented to anything or when you're using expressions to position things relative to the anchor point.
How It Works
Alright, so here’s what’s happening:
sourceRectAtTime(time, false)gives us the bounding box of the text—its width, height, and how far it’s offset from the layer’s top-left.s.leftands.toptell us where the box starts relative to the layer’s anchor.- By adding half the width and height, we get the center of the box.
- The result is a point that keeps your anchor locked to the center of the text—even if the text changes or animates.
This is especially useful when you're:
- Animating scale or rotation and want it to stay centered
- Swapping text dynamically (like with templates or Essential Graphics)
- Avoiding that annoying offset when your anchor is stuck in the top-left corner
Frequently asked questions
How do I use the expression on this page?
Just copy the full expression code from the top of this page. Then Alt-click (or Option-click on Mac) the stopwatch on the property you want to animate. Paste the code into the editor and that's it. If you’re not sure which property to use, check the "Where to Apply" section above.
The expression isn’t working. What should I check?
First, make sure your project is using the JavaScript engine (go to File > Project Settings > Expressions). Also double-check for missing characters, and see if the code requires parenting a layer. If so, there will be a comment in the code explaining what needs to be connected.
I’m not sure what the expression does. Where can I learn more?
Take a look at the "How It Works" section on this page. It explains each part of the expression in plain language so you can understand how everything works together.
Can I customize how the expression behaves?
Yes, absolutely. Most expressions include easy-to-edit variables near the top and comments that guide you on what to change. You can also link sliders or checkboxes using Expression Controls if you want more control in the timeline.
Can I apply this to other properties too?
Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.
Will it work in comps with different frame rates or sizes?
In most cases, yes. These expressions are designed to adapt to your comp’s resolution and frame rate. If anything specific needs adjusting, it’ll be noted in the code or in the "How It Works" section.
Related Expressions
Lock Gradient Ramp Position to Text
Locks the Gradient Ramp’s start and end points so they stay aligned with your text layer in comp space.

Typewriter Effect with Blinking Cursor
A versatile typewriter text animation that reveals characters progressively with a customizable blinking cursor, creating a realistic typing