Expression basics

Learn about the basics of creating and working with expressions.


When you want to create and link complex animations, but want to avoid creating tens or hundreds of keyframes by hand, try using expressions. An expression is small piece of JavaScript code that you can plug into animated properties in your After Effects projects, that evaluate to a single value for a single layer property at a specific point in time.

Unlike a script, which tells the application to do something, an expression tells a property to do something.. For example, you have a ball moving across the screen from left to right, but you also want that ball to wiggle. Rather than animating the Position property with keyframes, you can apply a wiggle expression to it.

The expressions language is based on the standard JavaScript language, but you do not need to know JavaScript to get started with expressions. You can create expressions by using the pick whip or by copying simple examples and modifying them to suit your needs. If you want to know more about it, see Understanding the Expressions language.

Here's a basic example of looping with expressions:

Why use expressions?

Save time and create animations quickly.
Expressions enable you to automate actions (such as wiggle, jitter or bounce). This saves significant time, in that you don't have to create new keyframes for each action. Here are a few examples to get you started.

Link different properties.

You can use expressions to link different properties such as Rotation and Position across compositions. Linking can help you create different animations without having to write different expressions for each. 

Create motion infographics.

You can use expressions when creating Motion Graphics templates. Adjust different properties, link animations, and modify the MOGRTs in After Effects. 

Control multiple layers to create complex animations.

The pick whip allows you to easily drive multiple animations from a few controls, creating animations which would take a lot more work using other features.

Create animated graphs and charts.

Quickly create animated and motion infographics such as a dynamic world map, and dynamic bar graphs indicating the pollution index of different countries.

Save and reuse expressions.

Save expressions as templates and reuse in other After Effects projects. No need to reinvent the wheel!

The expression UI

Before we get into working with expressions, the first step is to know the user interface. Use the following steps to get started:

  1. Create a comp, and select Layer > New > Solid to create a solid layer.

  2. In the Timeline panel, select the layer and press S on your keyboard to reveal the scale property. From here, your journey with expressions starts.


  3. Let's create an expression. In the timeline panel, Alt+Click (Win) or Opt+Click (Mac) the stopwatch next to Position to add an expression to the property. After Effects assigns default expressions to all the properties which you can modify later.

  4. Notice the changes in the user interface that take place from creating the expression. First, the value of the Scale property (shown as 100,100) changes from blue to red. The red color indicates that the value has an active expression.

    expression open

  5. See that a twirls has appeared to the left of the stopwatch, click it open. Use it to expose the expression itself.

    • The first button looks like an equals sign ("=") and toggles the expression on and off. It appears blue when the expression is enabled.
    • The second button toggles showing the expression's value over time in the Graph Editor.
    • The third button with the little spiral is the pick whip which you can use to help construct expressions. 
    • The fourth button opens the Expression Language menu, which can be used to help construct expressions.
    expression options

  6. Finally, to the right of the four buttons you can view the default expression transform.position. If you want to change the expression, click on the expression text in the Timeline to activate the expression editor field. It works just like any text field; copy, paste, select, or drag text. Pressing enter creates a new line, and you can resize the height. Click it and type the expression you want such as wiggle(3,50). To learn more, see Editing expressions.

    edit expression

Expressions and Keyframes

After you add an expression to a property, you can continue to add or edit keyframes for the property. An expression can take the value of a property as determined by its keyframes and use that as input to generate new, modified values. For example, the value+90 expression on the Rotation property of a layer adds 90 degrees to the value of the Rotation property, in addition to the keyframed motion:

Some methods—such as wiggle—operate directly on the existing property value. (See Property attributes and methods (expression reference).) 

The wiggle(10, 10) expression on the Position property of a layer preserves the keyframed motion of the layer and causes it to wiggle a little.

Using simple math in expressions

The values for a property that contains an expression appear in red or pink type.

A good way to begin working with expressions is to create a simple expression with the pick whip and then adjust the behavior of the expression using simple math operations, such as those listed in the following table:












Perform opposite of original, such as counterclockwise instead of clockwise.

For example, you can double the result by typing *2 at the end of the expression; or you can halve the result by typing /2 at the end of the expression.

As you develop comfort editing expressions, you can combine these simple operations—and more. For example, you can add /360*100 to the end of an expression to change its range from 0-360 to 0-100. This change would be useful if you wanted to convert the values of a 360-degree dial to a slider that is measured in percentages.

The Expression Language menu

expression language menu
Expression language menu

The Expression Language menu in the Timeline panel contains language elements specific to After Effects that you can use in an expression. This menu is helpful for determining valid elements and their correct syntax; use it as a reference for available elements. When you choose any object, attribute, or method from the menu, After Effects automatically inserts it in the expression field at the insertion point. If text is selected in the expression field, the new expression text replaces the selected text. If the insertion point is not in the expression field, the new expression text replaces all text in the field.

Common expressions you can use


Wiggle randomly

The wiggle expression is one of the most common After Effects expression. A wiggle expression does exactly what the same suggests - it causes a property to wiggle by a random amount. This expression can be used to make your scene seem more natural.

The numbers between the parentheses control the wiggle; the first number is the number of wiggles per second and the second number is the amount of wiggle. So, a Position property with an expression of wiggle(2,30) wiggles 2 times per second by up to 30 pixels.


Infinite rotating 40 degrees per second in time

The time expression is suitable for objects with perpetual motion. For example, if you want to have an object rotate indefinitely you can add the expression time to the Rotation property and the object rotates at 1 degree per second. It also works with basic math equations, so if you want to have the previous object rotate 40 times faster, use the expression time*40.


Loop in and out

If you use multiple keyframes to create repititive animation, it can be time consuming. Instead, use the loop expression to automate this and create complex looping animations. There are two types of looping - loopIn and loopOut (more commonly used). So, a Rotation property with an expression loopOut(); or loopOut("cycle"); loops your animation until the end of the timeline.

For more such examples, see Expression examples.

Edit an expression manually

  1. Enter text-editing mode by clicking in the expression field.


    When you enter text-editing mode, the entire expression is selected. To add to the expression, click within the expression to place the insertion point; otherwise, you will replace the entire expression.

  2. Type and edit text in the expression field, optionally using the Expression Language menu.
  3. To exit text-editing mode and activate the expression, do one of the following:
    • Press Enter on the numeric keypad.

    • Click outside the expression field.

Customize the appearance of expressions in the Expression Editor

Expression Editor in the Timeline panel
Expression Editor in the Timeline panel

You can customize how expressions look in the Expression Editor - located in the Timeline panel, using the Scripting & Expressions preferences. To open it, select After Effects > Preferences > Scripting & Expressions (Mac) or Application > Preferences > . Expressions (Win). To learn more, see Using the Expression Editor.    

Watch the following video to kickstart exploring expressions.

More Expression resources

Now that you have understood some of the concepts behind expressions, come to the community for some real-life examples, and to share your work.

You can also check out Dan Ebberts' excellent collection of example expressions and tutorials on his MotionScript website.

The AE Enhancers forum also provides many examples and much information about expressions, as well as scripts and animation presets.

Sigla Adobe

Conectați-vă la cont