User Guide Cancel

Expression basics

  1. After Effects User Guide
  2. Beta releases
    1. Beta Program Overview
    2. After Effects Beta Home
  3. Getting started
    1. Get started with After Effects
    2. What's new in After Effects 
    3. Release Notes | After Effects
    4. After Effects system requirements
    5. Keyboard shortcuts in After Effects
    6. Supported File formats | After Effects
    7. Hardware recommendations
    8. After Effects for Apple silicon
    9. Planning and setup
  4. Workspaces
    1. General user interface items
    2. Get to know After Effects interface
    3. Workflows
    4. Workspaces, panels, and viewers
  5. Projects and compositions
    1. Projects
    2. Composition basics
    3. Precomposing, nesting, and pre-rendering
    4. View detailed performance information with the Composition Profiler
    5. CINEMA 4D Composition Renderer
  6. Importing footage
    1. Preparing and importing still images
    2. Importing from After Effects and Adobe Premiere Pro
    3. Importing and interpreting video and audio
    4. Preparing and importing 3D image files
    5. Importing and interpreting footage items
    6. Working with footage items
    7. Detect edit points using Scene Edit Detection
    8. XMP metadata
  7. Text and Graphics
    1. Text
      1. Formatting characters and the Character panel
      2. Text effects
      3. Creating and editing text layers
      4. Formatting paragraphs and the Paragraph panel
      5. Extruding text and shape layers
      6. Animating text
      7. Examples and resources for text animation
      8. Live Text Templates
    2. Motion Graphics
      1. Work with Motion Graphics templates in After Effects
      2. Use expressions to create drop-down lists in Motion Graphics templates
      3. Work with Essential Properties to create Motion Graphics templates
      4. Replace images and videos in Motion Graphics templates and Essential Properties
      5. Animate faster and easier using the Properties panel
  8. Drawing, Painting, and Paths
    1. Overview of shape layers, paths, and vector graphics
    2. Paint tools: Brush, Clone Stamp, and Eraser
    3. Taper shape strokes
    4. Shape attributes, paint operations, and path operations for shape layers
    5. Use Offset Paths shape effect to alter shapes
    6. Creating shapes
    7. Create masks
    8. Remove objects from your videos with the Content-Aware Fill panel
    9. Roto Brush and Refine Matte
  9. Layers, Markers, and Camera
    1. Selecting and arranging layers
    2. Blending modes and layer styles
    3. 3D layers
    4. Layer properties
    5. Creating layers
    6. Managing layers
    7. Layer markers and composition markers
    8. Cameras, lights, and points of interest
  10. Animation, Keyframes, Motion Tracking, and Keying
    1. Animation
      1. Animation basics
      2. Animating with Puppet tools
      3. Managing and animating shape paths and masks
      4. Animating Sketch and Capture shapes using After Effects
      5. Assorted animation tools
      6. Work with Data-driven animation
    2. Keyframe
      1. Keyframe interpolation
      2. Setting, selecting, and deleting keyframes
      3. Editing, moving, and copying keyframes
    3. Motion tracking
      1. Tracking and stabilizing motion
      2. Face Tracking
      3. Mask Tracking
      4. Mask Reference
      5. Speed
      6. Time-stretching and time-remapping
      7. Timecode and time display units
    4. Keying
      1. Keying
      2. Keying effects
  11. Transparency and Compositing
    1. Compositing and transparency overview and resources
    2. Alpha channels and masks
    3. Track Mattes and Traveling Mattes
  12. Adjusting color
    1. Color basics
    2. Color management
    3. Color Correction effects
    4. OpenColorIO and ACES color management
  13. Effects and Animation Presets
    1. Effects and animation presets overview
    2. Effect list
    3. Effect Manager
    4. Simulation effects
    5. Stylize effects
    6. Audio effects
    7. Distort effects
    8. Perspective effects
    9. Channel effects
    10. Generate effects
    11. Time effects
    12. Transition effects
    13. The Rolling Shutter Repair effect
    14. Blur and Sharpen effects
    15. 3D Channel effects
    16. Utility effects
    17. Matte effects
    18. Noise and Grain effects
    19. Detail-preserving Upscale effect
    20. Obsolete effects
  14. Expressions and Automation
    1. Expressions
      1. Expression basics
      2. Understanding the expression language
      3. Using expression controls
      4. Syntax differences between the JavaScript and Legacy ExtendScript expression engines
      5. Editing expressions
      6. Expression errors
      7. Using the Expressions editor
      8. Use expressions to edit and access text properties
      9. Expression language reference
      10. Expression examples
    2. Automation
      1. Automation
      2. Scripts
  15. Immersive video, VR, and 3D
    1. Construct VR environments in After Effects
    2. Apply immersive video effects
    3. Compositing tools for VR/360 videos
    4. Advanced 3D Renderer
    5. Import and add 3D models to your composition
    6. Import 3D models from Creative Cloud Libraries
    7. Image-Based Lighting
    8. Extract and animate lights and cameras from 3D models
    9. Tracking 3D camera movement
    10. Cast and accept shadows
    11. Embedded 3D model animations
    12. Shadow Catcher
    13. 3D depth data extraction
    14. Modify materials properties of a 3D layer
    15. Work in 3D Design Space
    16. 3D Transform Gizmos
    17. Do more with 3D animation
    18. Preview changes to 3D designs real time with the Mercury 3D engine
    19. Add responsive design to your graphics 
  16. Views and Previews
    1. Previewing
    2. Video preview with Mercury Transmit
    3. Modifying and using views
  17. Rendering and Exporting
    1. Basics of rendering and exporting
    2. H.264 Encoding in After Effects
    3. Export an After Effects project as an Adobe Premiere Pro project
    4. Converting movies
    5. Multi-frame rendering
    6. Automated rendering and network rendering
    7. Rendering and exporting still images and still-image sequences
    8. Using the GoPro CineForm codec in After Effects
  18. Working with other applications
    1. Dynamic Link and After Effects
    2. Working with After Effects and other applications
      1. Export After Effects project as Premiere Pro project
    3. Sync Settings in After Effects
    4. Creative Cloud Libraries in After Effects
    5. Plug-ins
    6. Cinema 4D and Cineware
  19. Collaboration: Frame.io, and Team Projects
    1. Collaboration in Premiere Pro and After Effects
    2. Frame.io
      1. Install and activate Frame.io
      2. Use Frame.io with Premiere Pro and After Effects
      3. Frequently asked questions
    3. Team Projects
      1. Get Started with Team Projects
      2. Create a Team Project
      3. Collaborate with Team Projects
  20. Memory, storage, performance
    1. Memory and storage
    2. How After Effects handles low memory issues while previewing    
    3. Improve performance
    4. Preferences
    5. GPU and GPU driver requirements for After Effects
  21. Knowledge Base
    1. Known issues
    2. Fixed issues
    3. Frequently asked questions
    4. After Effects and macOS Ventura
    5. How After Effects handles low memory issues while previewing

Learn about the basics of creating and working with expressions.

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 a 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 don't 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 because 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 that would require much 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 them 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.

    expression

  3. Let's create an expression. In the Timeline panel, Alt+Click (Windows) or Opt+Click (macOS) 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, select 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. Select it and type the expression you want, such as wiggle(3,50). To learn more, see Editing expressions.

    edit expression

Expressions and Keyframes

All properties in After Effects that can be animated have a pre-expression value and a post-expression value

The pre-expression value is simply the value of the property before any expression is applied, either static or animated by keyframes. You can think of pre-expression values as similar to a layer's pixels without any effects applied. These pre-expression values can then be modified or used by an expression, just as an effect changes or uses the pixels of a layer, resulting in the post-expression value. 

The highlight color of the property's value in the UI indicates whether the property is using a pre-expression or post-expression value; pre-expression values are blue, while post-expression values are red.

The pre-expression value of any property can be accessed within an expression using the attribute value. For example, the expression value+90 on a Rotation property would add 90 degrees to the value the property had before the expression was applied. This also works for keyframed values; if the Rotation is keyframed from 0 to 45, the same value+90 expression will cause it to animate from 90 to 135. The keyframes' values can also be accessed similarly via key(index).value, using 1 for the index to get the first keyframe's value, 2 for the second, etc. The attribute numKeys will always be equal to the number of keyframes on the property, so key(numKeys).value is the value of the last keyframe.

Some methods, such as wiggle() or the various loops, implicitly use the pre-expression value. 

For example, the expression wiggle(10, 10) animates between -10 and 10 if a property has a value of 0, adding wiggling movement around its existing value. The same is true when the expression is applied to a keyframed property, creating secondary animation on top of the original animated values. See Property attributes and methods (expression reference).

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:

Symbol

Function

+

Add

-

Subtract

/

Divide

*

Multiply

*-1

Perform the opposite of the 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 isn't in the expression field, the new expression text replaces all text in the field.

Common expressions you can use

Wiggle

wiggle
Wiggle randomly

The wiggle expression is one of the most common After Effects expressions. A wiggle expression does precisely 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 is the number of wiggles. So, a Position property with an expression of wiggle(2,30) wiggles two times per second by up to 30 pixels.

Time

time*40
Infinite rotating 40 degrees per second in time

The time expression is suitable for objects with perpetual motion. For example, if you want an object to 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

loop_out
Loop in and out

If you use multiple keyframes to create repetitive 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.

    Note:

    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 Expression Editor,

  • macOS: Select After Effects > Preferences > Scripting & Expressions
  • Windows: Select Edit > Preferences > Scripting & Expressions

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.

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

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online