Auto Fade In & Out with Markers

Fades opacity in from the layer’s In Point to the first marker, and out from the second marker to the Out Point of the layer.

Author:
Denis Stefanides
Category:
Markers, Layer

Expression Code

// Make sure we have 2 markers
if (marker.numKeys < 2) {
  value; // fallback to current value if not enough markers
} else {
  fadeInStart = inPoint;
  fadeInEnd = marker.key(1).time;

  fadeOutStart = marker.key(2).time;
  fadeOutEnd = outPoint;

  if (time < fadeInStart) {
    0
  } else if (time <= fadeInEnd) {
    linear(time, fadeInStart, fadeInEnd, 0, 100) // fade in
  } else if (time <= fadeOutStart) {
    100 // fully visible
  } else if (time <= fadeOutEnd) {
    linear(time, fadeOutStart, fadeOutEnd, 100, 0) // fade out
  } else {
    0
  }
}
jsx

Where to Apply

Apply this expression to the Opacity property of any layer. It needs two markers:

  • First marker = end of fade-in

  • Second marker = start of fade-out

The actual fade lengths depend on how far those markers are from the in/out points of the layer.


How It Works

This expression gives you a nice auto-fade without having to manually key anything:

  • From the inPoint to the first marker, it fades from 0 to 100

  • Then it stays visible at 100

  • From the second marker to the outPoint, it fades from 100 to 0

  • Everything before and after is fully invisible

It’s especially useful for working with templates or reused comps where the in/out points and timing change, but you want the same fade logic every time.

Let me know if you want this version to also support optional comments or multiple marker sets!

Frequently asked questions

How do I use the expression on this page?

Just copy the full expression code from the top of this page. Then Alt-click (or Option-click on Mac) the stopwatch on the property you want to animate. Paste the code into the editor and that's it. If you’re not sure which property to use, check the "Where to Apply" section above.

The expression isn’t working. What should I check?

First, make sure your project is using the JavaScript engine (go to File > Project Settings > Expressions). Also double-check for missing characters, and see if the code requires parenting a layer. If so, there will be a comment in the code explaining what needs to be connected.

I’m not sure what the expression does. Where can I learn more?

Take a look at the "How It Works" section on this page. It explains each part of the expression in plain language so you can understand how everything works together.

Can I customize how the expression behaves?

Yes, absolutely. Most expressions include easy-to-edit variables near the top and comments that guide you on what to change. You can also link sliders or checkboxes using Expression Controls if you want more control in the timeline.

Can I apply this to other properties too?

Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.

Will it work in comps with different frame rates or sizes?

In most cases, yes. These expressions are designed to adapt to your comp’s resolution and frame rate. If anything specific needs adjusting, it’ll be noted in the code or in the "How It Works" section.