If you create an expression in After Effects to automatically fade a layer in and out, it can be efficient in the long run. This is because you’ll be able to adjust the beginning and ending times of the layer without having to adjust keyframes.

To get started, create an expression on your layer’s Opacity keyframe. Then, determine how long you want the fade to be. By setting a variable for this time, you can easily change it later if needed. For example, you can do:

fadeTime =.33;

This is basically 1/3 of a second, or ~10 frames in a 29.97 composition.

Next, create a variable for the fade in and use the linear expression. One of my previous tutorials covers the linear expression. It is written as:

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

In our case, the variable will be time because we’re looking at when a layer starts. The varMin is exactly the time the layer starts, which is written as inPoint. The varMax is when the fade should end. In our case that is inPoint+fadeTime that we set previously. Then value1 and value2 are 0 and 100, which is the starting and ending opacity.

Written out, it looks like this:

fadeIn=linear(time,inPoint,inPoint+fadeTime, 0, 100);

Next, we create a variable for the fade out and use another linear expression. Since we are dealing with the layer’s out point, we can use outPoint. The varMax in this instance is when the fade starts, or outPoint-fadeTime. Written out, it looks like this:

fadeOut=linear(time,outPoint,outPoint-fadeTime, 0, 100);

Finally, we combine the two to get the output:

fadeIn-fadeOut;

In entirety, the expression looks like this:

fadeTime =.33;

fadeIn=linear(time,inPoint,inPoint+fadeTime, 0, 100);

fadeOut=linear(time,outPoint,outPoint-fadeTime, 0, 100);

fadeIn-fadeOut;

To change the length of fade, change the numeric value .33 to whatever you desire. You can change the layer’s starting and ending points as desired and the fade will adjust accordingly thanks to the expression.

Check out the short After Effects tutorial video here: