How To Use The After Effects Linear Expression

The linear expression in Adobe After Effects maps one value range to another, enabling dynamic animations like scaling or positioning based on sliders or audio levels. Practical examples and resources from Envato Tuts+ and Artlist demonstrate its use in creating responsive bar graphs, text positioning, and audio-reactive visuals.

June 7, 2025

Join MILLIONS of users who have unleashed their true potential with Envato's new templates

Unlock Unlimited Creative Assets

How to Use the After Effects Linear Expression

Adobe After Effects is a cornerstone tool for motion designers, animators, and visual effects artists, offering a wide range of features to bring creative visions to life. Among its most powerful capabilities are expressions, which allow you to control layer properties programmatically. One of the most versatile and commonly used expressions is the linear expression, which enables you to map one range of values to another proportionally. This is particularly useful for creating dynamic animations, linking properties with different scales, or building interactive templates.

In this comprehensive guide, we’ll explore what the linear expression is, how it works, and how to use it effectively in After Effects. We’ll also provide practical examples to illustrate its real-world applications.

After Effects Templates from Arlist

What is the Linear Expression?

The linear expression in After Effects is a function that performs linear interpolation between two values based on an input value’s position within a specified range. Its syntax is:

linear(var, varMin, varMax, value1, value2)

  • var: The input value you want to map (e.g., a slider value, time, or audio level).
  • varMin: The minimum value of the input range.
  • varMax: The maximum value of the input range.
  • value1: The output value when var is at varMin.
  • value2: The output value when var is at varMax.

For any value of var between varMin and varMax, the linear expression calculates a proportional value between value1 and value2. This makes it ideal for scenarios where you need to connect properties that don’t share the same scale, such as a slider (0-100) controlling a layer’s scale (0%-200%).

For example, if you want a layer’s opacity to transition from 20% to 80% over 6 seconds, you could use:

linear(time, 0, 6, 20, 80)

This maps the time (0 to 6 seconds) to opacity values (20% to 80%).

Why Use the Linear Expression?

The linear expression is invaluable when you need to create proportional relationships between properties that have different value ranges. Here are some common scenarios:

  • Linking Sliders to Properties: A slider might range from 0 to 100, but you want it to control a layer’s opacity (0%-100%) or scale (0%-200%).
  • Data Visualizations: Animate bar graphs or charts where the height or size corresponds to a value from a slider or data source.
  • Audio-Reactive Animations: Make visual elements respond to audio levels, such as scaling a shape based on music amplitude.
  • Template Creation: Build user-friendly templates where users control properties within specific ranges, ensuring predictable results.

Without the linear expression, you’d need to manually adjust keyframes or perform complex calculations. The linear expression automates this process, saving time and enhancing precision.

How to Use the Linear Expression

To apply the linear expression in After Effects, follow these steps:

  1. Identify the Input and Output Properties:
    • Determine the property you want to control (e.g., scale, position, opacity).
    • Identify the input value (e.g., a slider, audio level, or time).
  2. Define the Ranges:
    • Set the input range (varMin to varMax).
    • Set the output range (value1 to value2).
  3. Apply the Expression:
    • Select the property in the Timeline panel (e.g., scale).
    • Click the stopwatch icon to open the expression field (or Alt-click on Windows, Option-click on macOS).
    • Enter the linear expression, ensuring you reference the correct input property using the pick whip or by typing the property path.
  4. Test and Adjust:
    • Adjust the input values and observe how the output property changes proportionally.
    • Fine-tune the ranges to achieve the desired effect.

For example, to link a slider to a layer’s scale, you might use:

linear(thisComp.layer("Control").effect("Slider Control")("Slider"), 0, 10, 0, 100)

This maps a slider’s value from 0 to 10 to a scale from 0% to 100%.

Practical Examples of Linear Expression

Below are several practical examples of how the linear expression can be used in After Effects, drawn from various sources and scenarios.

Example 1: Resizing a Bar Graph

Suppose you’re creating a bar graph where the height of the bar should correspond to a value from a slider or audio level. The bar’s scale might range from 0% to 100%, but your input value ranges from 0 to 10. You can use the linear expression to map the input value to the bar’s scale.

Expression:

linear(thisComp.layer("Control").effect("Slider Control")("Slider"), 0, 10, 0, 100)

  • Explanation:
    • thisComp.layer("Control").effect("Slider Control")("Slider"): References the slider value on a control layer.
    • 0, 10: The input range (slider goes from 0 to 10).
    • 0, 100: The output range (bar scale goes from 0% to 100%).

This ensures that when the slider is at 0, the bar’s scale is 0%, and when the slider is at 10, the bar’s scale is 100%. For any value in between, the bar’s scale will be proportionally interpolated.

Use Case: This is ideal for data visualizations, such as animating charts or graphs based on user input or data.

Example 2: Positioning Text on a Bar Graph

In the same bar graph scenario, you might want a text layer to sit on top of the bar, moving up and down as the bar’s height changes. You can use the linear expression to position the text based on the bar’s scale.

Expression for Text Position:

[bar.position[0], linear(thisComp.layer("Control").effect("Slider Control")("Slider"), 0, 10, bar.position[1], bar.position[1] - (bar.height * (100 - scale)/100))]

  • Explanation:
    • bar.position[0]: Keeps the text horizontally aligned with the bar.
    • linear(...): Maps the slider value (0-10) to the vertical position of the text, ensuring it stays on top of the bar as its height changes.
    • bar.height * (100 - scale)/100: Adjusts the position based on the bar’s height and scale.

Alternatively, you can parent the text layer to the bar and adjust its anchor point for simpler positioning, but the expression provides more dynamic control.

Use Case: This is useful for creating dynamic labels in data visualizations, ensuring text stays aligned with animated elements.

Example 3: Mapping Audio Levels to Visual Elements

Another common use case is making visual elements react to audio levels. For example, you can make a layer’s size or position change based on the amplitude of an audio track.

Expression:

linear(thisComp.layer("AudioLayer").effect("Both Channels")("Slider"), 0, 20, 700, 200)

  • Explanation:
    • thisComp.layer("AudioLayer").effect("Both Channels")("Slider"): References the audio level (ranging from 0 to 20) generated by the “Convert Audio to Keyframes” command.
    • 0, 20: The input range (audio level).
    • 700, 200: The output range (e.g., position or size of a layer).

This expression could be applied to a layer’s position, scale, or other properties, making it dynamically respond to the audio. For instance, it could move a layer vertically from 700 pixels to 200 pixels as the audio amplitude increases.

Use Case: This is perfect for creating audio-reactive visuals, such as music videos or promotional animations where elements pulse or move with the beat.

Example 4: Controlling Shape Size with a Slider

Suppose you’re creating an After Effects template and want users to control the size of a shape layer with a slider (0-100), but you want the shape’s scale to range only from 5% to 20%. The linear expression can map these ranges effectively.

Expression:

linear(thisComp.layer("Control").effect("Slider Control")("Slider"), 0, 100, 5, 20)

  • Explanation:
    • thisComp.layer("Control").effect("Slider Control")("Slider"): The slider value (0-100).
    • 0, 100: The input range (slider).
    • 5, 20: The output range (shape scale).

This ensures that the shape’s scale stays within the desired 5%-20% range, providing controlled flexibility for template users.

Use Case: This is ideal for creating user-friendly templates where you want to limit the range of adjustments to maintain design consistency.

Advanced Tips for Using Linear Expression

  • Combine with Other Expressions: The linear expression can be combined with other expressions like wiggle or clamp for more complex animations. For example, you can create a looping wiggle effect with smooth transitions using:
  • t = time % secondsToLoop;
    wiggle1 = wiggle(frequency, amplitude, 1, 0.5, t);
    wiggle2 = wiggle(frequency, amplitude, 1, 0.5, t - secondsToLoop);
    linear(t, 0, secondsToLoop, wiggle1, wiggle2)
  • This creates a smooth transition between two wiggle states over a specified loop time.
  • Use with Audio Keyframes: Combine the linear expression with the “Convert Audio to Keyframes” command to create audio-reactive animations, as shown in Example 3.
  • Create Custom Controls: Use the linear expression to build user-friendly templates by mapping slider inputs to specific property ranges, ensuring predictable results for end-users.
  • Debugging: If the expression doesn’t work as expected, check the input property path (e.g., ensure the slider or audio layer is correctly referenced) and verify that the input and output ranges are appropriate.

Conclusion

The linear expression in After Effects is a powerful tool that allows for precise control over animations by mapping one range of values to another. Whether you’re creating data visualizations, interactive templates, or audio-reactive visuals, understanding and utilizing the linear expression can significantly enhance your workflow and the quality of your projects.

By experimenting with different input and output ranges, you can unlock the full potential of the linear expression, creating dynamic and responsive animations that elevate your After Effects projects. Resources like Envato Tuts+ and Artlist provide valuable guidance for learning and applying expressions in real-world scenarios.

Start incorporating the linear expression into your projects today, and explore how it can streamline your animation process and bring your creative ideas to life!