STEAL these 10 text expressions for perfect After Effects templates

  -  
February 10, 2025
  -  
Text expressions for after effects thumbnail
Ivan Stankov
This article was written by Ivan, Creative Director at Plainly. He has over 6 years of experience in the video editing and motion design industry. Ivan is passionate about sharing his expertise with video editors, motion designers, and those aspiring to enter the field.

After Effects expressions can be a game-changer when it comes to efficiency and flexibility in motion design. Today, we’re breaking down 10 powerful expressions specifically for text layers that will save you time and take your templates to the next level. And trust us, there’s one expression in here that will COMPLETELY change how you work!

So, let’s get into it!

10. text.sourceText

This is the foundation of working with text expressions. It allows you to link text layers, merge inputs, and dynamically add custom prefixes or suffixes.

Simply connect one layer’s Source Text to another or combine multiple text layers into a single one. It’s a simple yet incredibly useful expression to keep your projects organized and dynamic.

text.sourceText

9. Lock Anchor Point

Nothing ruins a design faster than text shifting around because of a misaligned anchor point. This expression keeps your anchor point perfectly centered, no matter how many lines of text you add.

It works great for paragraph text when creating headlines or lower-thirds. If you want to lock the anchor point to a specific corner, just tweak the expression accordingly.

top = sourceRectAtTime().top;
left = sourceRectAtTime().left;
x = left + (sourceRectAtTime().width / 2);
y = top + (sourceRectAtTime().height / 2);
[x, y];

8. Auto-Scaling Text to Fit Width

Ever had text spill outside the safe zone and wreck your layout? Yeah, we don’t want that…

This expression automatically scales your text to fit within a predefined width, making it a lifesaver for templates where text length is unpredictable.

textWidth = sourceRectAtTime(time, false).width;
defaultLimit = thisComp.width;
customLimit = effect("Width Limit")("Slider");
widthLimit = (customLimit > 0) ? customLimit : defaultLimit;
if (textWidth > 0) {
   scaleFactor = (widthLimit / textWidth) * 100;
   clampedScale = clamp(scaleFactor, 0, 100);
   [clampedScale, clampedScale];
} else {
   value;
}

7. Replace Spaces with New Lines

If you’re pulling text from a CSV, Excel file, or API, you’ll love this one. This expression replaces spaces with line breaks, making text automatically stack vertically.

text.sourceText.replace(/ /g, "\r");

6. split()

The split() function is perfect for breaking text into multiple parts, making it incredibly useful for inputs like names, dates, or other structured data.

text.sourceText.split(" ")[0]; // First part
text.sourceText.split(" ")[1]; // Second part

5. repeat()

Want to repeat your text input multiple times? Whether it’s letters, words, or entire phrases, this expression does the job. You can even connect it to a slider for intuitive control.

repeat(0); // Replace 0 with a number or a Slider Control

4. Character and Word Counters

These expressions are incredibly useful for adjusting font size dynamically, changing styling based on word count, or triggering animations based on text length.

myText = thisComp.layer("Source").text.sourceText;
myText.lengthmyText = thisComp.layer("Source").text.sourceText;
myText.split(" ").length;

3. Two-Layer Center Alignment

This expression keeps two text layers aligned regardless of their length—perfect for lower-thirds, CTA screens, or dynamic titles.

sr1 = thisLayer.sourceRectAtTime();
sr2 = thisComp.layer("Text 2").sourceRectAtTime();
margin = thisComp.layer("Text 2").position[0];

x = sr1.width - margin - sr2.width;
[thisComp.width / 2, thisComp.height / 2] + [x / 2, sr1.height / 2];

2. Automatic Fade In and Fade Out

Every text layer needs an in and out animation. This expression automates the process so you never have to adjust keyframes manually.

fadeDuration = effect("Fade Duration")("Slider");
finalValue = effect("Final Value")("Slider");
zeroValue = effect("Zero Value")("Slider");
enableFadeIn = effect("Enable Fade In")("Checkbox") == 1;
enableFadeOut = effect("Enable Fade Out")("Checkbox") == 1;

currentTime = time - inPoint;
timeToEnd = outPoint - time;

if (enableFadeIn && currentTime < fadeDuration) {
   t = currentTime / fadeDuration;
   fadeValue = ease(t, 0, 1, zeroValue, finalValue);
} else if (enableFadeOut && timeToEnd < fadeDuration) {
   t = (fadeDuration - timeToEnd) / fadeDuration;
   fadeValue = ease(t, 0, 1, finalValue, zeroValue);
} else {
   fadeValue = finalValue;
}
fadeValue;

1. Dynamic Number Counter without Keyframes

This expression lets you create a dynamic number counter WITHOUT keyframes—just use sliders or text layers for start and end values. Perfect for infographics, data visualization, or automated videos.

value1 = effect("Start Value")("Slider");
value2 = effect("End Value")("Slider");
animationDuration = effect("Duration")("Slider");
decimals = effect("Decimals")("Slider");

startTime = inPoint;
endTime = startTime + animationDuration;
t = clamp(time, startTime, endTime);

animatedValue = linear(t, startTime, endTime, value1, value2);

decimals = Math.round(decimals);
roundedValue = animatedValue.toFixed(decimals);

roundedValue;

Final Thoughts

And that’s a wrap! These 10 text expressions are guaranteed to save you time and supercharge your After Effects templates—making them work every single time in every single situation.

If you want even more expressions like these, check out our After Effects Expressions Library for 100+ free expressions to level up your workflow.

Read more similar articles

Thumbnail for Celtra alternatives & competitor

Best 6 Celtra alternatives in 2025 [By a Non-competitor]

Read more
Smartly alternatives thumbnail

Best 7 Smartly alternatives 2025 [By a non-competitor]

Read more
Video marketing metrics thumbnail

8 Video marketing metrics you can’t afford to ignore

Read more

Start automating video creation now.

a mesh of elegant lines transparent image