Ae

Dynamic Text Box

Basic

Learn in 10 min how to create a dynamic text box that changes size automatically to the text, on one text layer without complex expressions with any font, in Adobe After Effects.

This style is everywhere! Use this for your titles, your lower thirds, anything where you present text. I use this for all the text boxes in these tutorials, as this technique is so versatile and speeds up the creation process.


To get started, as this tutorial is all about creating this look on one layer, in a new composition create a new text layer and type out some text.

Next we will add some expression controls to our text layer to give us control over the resulting box.

Add the following as Slider Controls (from the Expression Controls menu) and rename by hitting Enter:

And we will also add a Color Control and call it Box Color.

Next we need to add the effects needed to make this look come alive. So add the following effects:

With our effects added we need to add in our expressions for the CC RepeTile effect.

 

Code Snippet
Expand Right
effect("CC RepeTile")("Expand Up") + effect("Additional Right")("slider");
Code Snippet
Expand Left
effect("CC RepeTile")("Expand Up") + effect("Additional Left")("slider");
Code Snippet
Expand Down
effect("CC RepeTile")("Expand Up");
Code Snippet
Expand Up
try
try{ } catch(err){ }

Think of try and catch like a game of tag, with the aim being to try and avoid getting tagged. If you do not succeed in what you are trying (try) to do, then you will get caught (catch).

Similarly in coding, the program will try anything in the try{} brackets. If it fails for whatever reason, it will trigger any code found in the catch(){} function instead.

Including err as a parameter of catch() will capture details on the error that caused the try{} to fail.

Typically in something like After Effects, try{} is used to test out and see if particular scenarios are true, especially ones that do not have an inherent way to check a value, such as whether a layer has a parent etc.

{
0.15 * parent.transform.scale[0] - 3 + effect("Expand Edge")("slider");
}
catch(err){
0.15 * transform.scale[0] - 3 + effect("Expand Edge")("slider");
}

We need to add expressions to the Beam Starting Point and Ending Point to keep it positioned correctly, so we will add the following.

Code Snippet
Starting Point
[0, thisComp.height/2]
Code Snippet
Ending Point
[thisComp.width, thisComp.height/2]

That is how you create this text box effect on the one layer using minimal effects and minimal expressions, without requiring monospaced fonts.

SUPPORT MEDIA WORKBENCH ON PATREON FOR EXCLUSIVE DOWNLOADS
How do I add opacity control independently for the box and for the text?

I tried a bunch of ways to do this with some results better than others. The easiest way I have found that gives you a lot of control while not having to mess around too much is to do the following.

  1. Follow the tutorial to the end so you have all the effects controls in.
  2. Go to Channel
  3. Blend and add it between the “Beam” and “CC Composite” Effects. You don’t need to change any settings of the “Blend” effect.
  4. Go to the “CC Composite” effect directly below it and uncheck “RGB Only” and ensure the Composite Original is set to “In front”
  5. Finally, go to the “Blend” effect and the adjust the “Blend with Original” percentage to adjust the opacity of the box to your liking.

This works with any box colour and text colour and lets you keyframe the box opacity as a percentage. You can control the text opacity independently as well by using the Opacity property in the “CC Composite” effect.

Adding this one additional effect gives you a separate property you can keyframe for…

  • Text Colour
  • Text Opacity
  • Box Colour
  • Box Opacity
Can you add a control for box roundness?

You could fake rounded edges with the layer effect -> stroke and make it the same color as your box. There’s probably other ways as well using one of the Keying effects to refine the edge or something.

How would you add two more additional controls to expand the box just up or just down?

To add in two more controls you’ll need to do the following…

  1. Add another slider control for “Additional Top” and “Additional Down” plus one more that you can call “expansion”
  2. Around 2:19 in the video. Instead of linking each of the repe tile properties to the Expand Up property, you would instead link it to the “expansion” slider, then + your “additional” slider.
  3. The expression at 2:42 that goes into the Expand Up in the video, you would write as an expression on your “expansion” slider.
How do I animate the text?

There is a separate tutorial on how to do this found in the related videos section.

How can you get box stroke instead fill effects?

Do the following…

  1. Effect -> Matte -> Simple Choker
    Adjust the Choke Matte into the negative so you start seeing a black border around the edge.
  2. Effect -> Channel -> Minmax
    Set Channel to “Alpha” then adjust the radius to expand or shrink the black border.
  3. If you want a white border use Channel -> Invert and then adjust the box and text colours.Or if you want any other colour border
  4. Effect -> Color Correction -> Change to Color
    Set From Black to whatever colour.
    Change : HLS.
    Change by : Transforming to color.

Grab some Merch

Express your inner creative outwardly whilst supporting all that we do...

View Merch store

Need some help

Run into an issue with one of the tutorials or is something not covered in the FAQ?

Contact and Support