After Effects Expressions 101

Expressions are possibly the most powerful feature in After Effects, but a lot of animators don’t use them because they seem intimidating. It takes a little bit of time to really get the hang of using them, but it’s worth the time investment. Once you learn how to set up behaviors and controls without having to do tons of manual keyframing, you’ll be a much faster and more efficient motion graphics artist.

This lesson is a quick overview of how expressions work in After Effects. You’ll learn what expressions are, why you may want to use them, and how to apply them to properties in your comps. We’ll use a simple example, animating the hands on a clock, to work through the basics. Once you’ve watched this video, you should have enough knowledge to move on to some of the more advanced lessons that use expressions.

If you want to know even more about expressions, check out the Resources tab for more places to learn.

If you have any questions, click over to the Q&A tab to post them. Other students can answer you, and we’ll put our team on the case to try and get you a solution ASAP.

Here are some amazing sites to check out that will help you get the hang of expressions.

Motion Script


AE Enhancers

aescripts + aeplugins

    • Where do I get the project files?

    • I'm very sorry for the miscommunication. This one of our older lesson videos and it unfortunately does not include a project file download. The introduction to the video was added separately when we relaunched our side and I apologize that it is inaccurate in this instance.

    00:00:11,262- Hey, there. Joey here for School of Motion,
    00:00:13,040and in this lesson, we'll be taking a look
    00:00:14,957at the basics of Expressions and After Effects.
    00:00:17,787If you've never used Expressions before,
    00:00:19,901or even if you have, but maybe need a little refresher,
    00:00:22,864this lesson will get you going in the right direction.
    00:00:25,415We'll check out what Expressions are,
    00:00:27,299how to use them,
    00:00:28,661and why as a MoGraph artist, you need to know about them.
    00:00:31,877Don't forget to sign up for a free student account,
    00:00:33,707so you can grab the project files
    00:00:35,415and Expressions from this lesson,
    00:00:36,926as well as assets from any other lesson on the site.
    00:00:39,850And now, let's jump in.
    00:00:42,863- [Narrator] So if you look at this comp here,
    00:00:46,066you'll see that I've set up a really, really simple scene,
    00:00:49,869with a background and a clock,
    00:00:51,444and I've already done the PhotoShop work
    00:00:54,766of separating out the hour and minute hands
    00:00:57,656of the clock.
    00:00:59,128And I've also set the anchor point appropriately
    00:01:03,249to the center of rotation of the two hands.
    00:01:06,186So if I route the minute hand,
    00:01:07,679you'll see that it rotates exactly as it should.
    00:01:12,561So if you were asked to animate a scene
    00:01:15,520that had a clock in it,
    00:01:18,832there's an easy way to do it,
    00:01:20,724but there's some pitfalls with that easy way,
    00:01:22,592and I'm gonna show you that right now.
    00:01:24,162So obviously, the easiest way would be to
    00:01:26,432set a key frame on the rotation property at the beginning.
    00:01:30,272So let's do that.
    00:01:32,177And then to go forward in the comp,
    00:01:36,112and change the values.
    00:01:37,034So now you have two key frames, alright?
    00:01:40,662So you can see that this works.
    00:01:45,125let's say that you want a very exact speed
    00:01:50,205for the amount of rotation of the minute hand.
    00:01:54,332Let's say that you want one rotation
    00:01:58,062every two and a half seconds,
    00:02:00,265or something like that.
    00:02:01,932Well, now it gets a little bit trickier.
    00:02:03,526Because now you have to say,
    00:02:04,802okay, well how long is my comp?
    00:02:06,622Well this comp is two minutes long.
    00:02:09,447If I'm having one rotation every two and a half seconds
    00:02:12,549then what does this value need to be?
    00:02:15,282And you have to do math, and no one likes to do math.
    00:02:18,842So when you're using key frames,
    00:02:21,852it's good if you're doing short, little bursts of animation.
    00:02:26,499But when you're doing things like this,
    00:02:28,175where you need a constant motion throughout
    00:02:30,395the length of your comp,
    00:02:31,825Expressions are a much better way to do it.
    00:02:35,475So I'm just gonna use this as an example
    00:02:37,587of how to apply an Expression,
    00:02:39,044and sort of how you can work
    00:02:40,249with Expressions and After Effects.
    00:02:42,349So let's get rid of this key frame,
    00:02:44,279and let's zero this back out.
    00:02:47,519So the first thing we wanna do is actually enable
    00:02:50,549an Expression on this layer, alright?
    00:02:53,426And Expressions are applied to key frame-able properties
    00:02:56,929like position, scale, rotation, transparency,
    00:02:59,769or if you had an effect on this layer,
    00:03:01,674you could apply Expressions to the properties of the effect.
    00:03:05,609You can use them a lot of ways.
    00:03:09,910One way you can apply an Expression
    00:03:11,531is to click on the property that you want
    00:03:13,411to add the Expression to,
    00:03:15,371go to the animation menu and hit add Expression.
    00:03:20,637I'm a big fan of hotkeys,
    00:03:23,077and whenever possible I'm gonna try and teach you guys
    00:03:26,730some really useful hotkeys because if you're trying
    00:03:29,955to freelance, or impress your employer,
    00:03:33,497or get a job, one of the best things that you can
    00:03:37,257do as a Motion Graphics artist is get quicker,
    00:03:40,795and be able to work faster and build things faster,
    00:03:44,545and hot keys are probably the number one way to do that
    00:03:48,154because when you get the hang of them,
    00:03:50,497you'll find that you start doing them
    00:03:53,287without even thinking about it,
    00:03:54,807and you can work almost as fast as you can think.
    00:03:57,717And that's really important.
    00:03:59,562So the way I add Expressions is I hold the Option key,
    00:04:03,569and by the way, I'm on a Mac.
    00:04:04,989On a PC, I would imagine that's the ALT key.
    00:04:09,339So you hold Option, and you click Rotation,
    00:04:11,639and now we've enabled an Expression for that.
    00:04:14,267You can see the value of Rotation turned red,
    00:04:16,929and we've got this box over here
    00:04:18,387where we can type our Expression.
    00:04:20,559Now, the fastest way to use Expressions is to kinda
    00:04:24,539learn the four, five or six that you use most often,
    00:04:27,789and just kinda memorize them.
    00:04:29,959And it's not as hard as it sounds,
    00:04:32,039after you've used an Expression two or three times,
    00:04:33,969you'll probably remember it.
    00:04:36,009But if you forget,
    00:04:38,406or if you're just new to Expressions,
    00:04:40,696and you're not even sure what Expressions are out there,
    00:04:43,992this little arrow can be your buddy because
    00:04:46,532you can click this arrow,
    00:04:48,252and After Effects has a built-in dictionary
    00:04:51,941of all of the different Expression variables
    00:04:55,062and functions that you can use,
    00:04:57,051and it even gives you hints about how to use them.
    00:05:01,231You'll see some of these functions have
    00:05:04,922extra kind of options
    00:05:06,227that are inside of parenthesis,
    00:05:07,695and that tells you that if you use, for example,
    00:05:10,153this random function which returns a random number,
    00:05:14,246you need to need add a parenthesis,
    00:05:16,218and put the minimum value, or array, comma,
    00:05:19,199and then the maximum value, or array.
    00:05:21,546So you may not totally understand that yet at this point,
    00:05:24,728but just bare with me, this will all make sense.
    00:05:28,578Just know that once you start using Expressions
    00:05:31,668if you suspect that an Expression exists
    00:05:34,893to do what you want, you can look through this menu,
    00:05:36,880and you might just find it.
    00:05:39,888So what we wanna do is
    00:05:42,932find a way to have the rotation
    00:05:45,872increase at a constant rate throughout the comp, alright?
    00:05:49,350Now the best trick I know to do that is to tie the rotation
    00:05:53,961to something that's already naturally moving,
    00:05:57,251increasing at a constant rate,
    00:05:58,936and that would be the time of the comp, alright?
    00:06:02,388And you can find the variable for the comp time
    00:06:06,288in the Global section here, it's just Time,
    00:06:09,496or we can type it in.
    00:06:11,216This one's pretty easy to remember,
    00:06:12,756so we type in Time,
    00:06:15,446and a good habit to get into is adding a semi-colon
    00:06:18,589at the end of all of your Expressions.
    00:06:21,446If you have a one-line Expression like Time,
    00:06:24,236you technically don't need to use the semi-colon,
    00:06:26,351but once you get into multi-line Expressions,
    00:06:28,848After Effects will require every line to have a semi-colon,
    00:06:32,341otherwise it sorta doesn't know where
    00:06:34,088one line ends and the next one begins.
    00:06:36,901When you're editing your Expressions to commit them,
    00:06:40,711on the Mac you can hold Command and hit Return,
    00:06:43,831or you can hit the Return that's on the number pad,
    00:06:46,831and on a PC, it would be whatever
    00:06:48,721the equivalent keystroke is for Command,
    00:06:50,851it's probably CTRL.
    00:06:53,231So now as we scrub through this,
    00:06:55,381you'll see that the minute hand
    00:06:57,914is moving at a constant speed.
    00:07:00,946It's moving very slowly, but it's moving
    00:07:03,413at the same speed the entire length of the comp,
    00:07:05,789and this is great because if all of the sudden
    00:07:07,798I needed to make this comp ten minutes long,
    00:07:10,319I wouldn't have to change anything,
    00:07:11,994it would still be animating at that same speed.
    00:07:16,194Now the reason it's going so slow is because
    00:07:19,344this time variable,
    00:07:22,217it returns the comp time in seconds.
    00:07:25,564So if we go to five seconds, for example,
    00:07:30,707you'll see that the rotation is set to five.
    00:07:35,057And the reason that I know this is because
    00:07:37,907I have used the Expression Reference many, many times
    00:07:42,210and this is where you wanna go
    00:07:44,084if you wanna use an Expression,
    00:07:45,729but you're not sure how.
    00:07:47,099There's actually pretty good documentation for it.
    00:07:49,661And there's also some great websites out there
    00:07:51,959that will help you learn to do this stuff,
    00:07:54,239and there's a lot great
    00:07:56,319pre-built Expressions that people
    00:07:58,157have put out there for free, and you can use them,
    00:08:00,519and they're very helpful.
    00:08:02,251And I'll put some links to those in this blog post.
    00:08:04,959So back to our Expression, time is not doing it for us.
    00:08:08,727It's making the minute hand move too slowly.
    00:08:11,957So with Expressions, you can do simple math very easily.
    00:08:16,597So what if we took that value, Time,
    00:08:19,757and we multiplied by a number to increase the rate
    00:08:23,957at which the minute hand's turning?
    00:08:25,805So let's say that we wanted the minute hand to
    00:08:29,370make one complete rotation every three seconds.
    00:08:32,690So what that means is we would need it
    00:08:35,100to turn 360 degrees in three seconds.
    00:08:39,048So hopefully, you can do simple math (laughs)
    00:08:43,328because it is helpful.
    00:08:44,618So if you divide 360 into three seconds,
    00:08:47,908it's 120 degree per second.
    00:08:51,078So every second, we want to multiply
    00:08:53,978whatever Time it is, times 120.
    00:08:57,408To multiply things in After Effects,
    00:08:59,480you use the asterisk.
    00:09:01,818When you're doing math, you use the plus sign,
    00:09:04,768the minus sign, the asterisk for multiplication,
    00:09:08,138and a forward slash for division.
    00:09:11,828And those are the four operators
    00:09:13,328that you'll use most the time.
    00:09:15,308So if we type in Time times 120,
    00:09:17,748hold Command and hit Return,
    00:09:19,508you'll see now that minute hand is moving much faster.
    00:09:23,601And you can see every three seconds, if we go to three.
    00:09:30,198We have had one rotation in three seconds, alright?
    00:09:34,208So now let's focus on the hour hand.
    00:09:37,218So for the hour hand,
    00:09:38,051I'm gonna hit R to open up the rotation properties,
    00:09:40,291I'm gonna hold Option, click Rotation to add an Expression.
    00:09:43,918So now the hour hand, we need the same idea,
    00:09:47,908we just need it to move slower.
    00:09:49,698So let's type in Time times.
    00:09:53,388So now you just gotta kinda use a little bit of logic here,
    00:09:57,868if the minute hand rotates once around this,
    00:10:02,108how far does the hour hand go?
    00:10:04,531Well it goes from one number to the next, right?
    00:10:08,438So there's twelve numbers,
    00:10:10,311so that means basically divide that circle
    00:10:12,455into twelve pieces, right?
    00:10:14,588So really I just need to divide this number, 120, by twelve.
    00:10:20,743So that's how far it'll move,
    00:10:22,081so 120 divided by twelve is ten.
    00:10:26,491That's pretty easy.
    00:10:28,178And so now, you can see here, we're at nine o' clock,
    00:10:32,751and that minute hand's gonna go all the way around,
    00:10:35,083and now we're at ten o' clock, alright?
    00:10:36,931So we now have set up an accurately functioning clock,
    00:10:40,996with no key frames, this clock could go
    00:10:44,796as long as we make this comp.
    00:10:46,354We can make this an hour,
    00:10:47,826and this clock would just keep running indefinitely,
    00:10:50,269and it would always tell the right time which is great.
    00:10:55,136This is just a quick example of how Expressions
    00:10:57,546can be useful and can save you a lot of time.
    00:11:00,375If you had to key frame this, it would be a pain.
    00:11:02,908And before we end the tutorial,
    00:11:04,200I wanna show you one other quick thing
    00:11:08,123about Expressions that's probably
    00:11:09,712my favorite thing about Expressions.
    00:11:12,254And this is the ability to set up controls
    00:11:16,399for things like this.
    00:11:18,749I'll show you what I mean by that.
    00:11:20,379So what I'm gonna do is I'm gonna add a Null Object, right?
    00:11:24,629And if you don't use Null Objects,
    00:11:26,661you should get into the habit of using them.
    00:11:29,024They are just objects in After Effects
    00:11:30,965that have no image associated with them.
    00:11:33,367They don't look like anything,
    00:11:35,077but they're sort of like a utility layer,
    00:11:37,240and you can use them to parent things.
    00:11:41,677I can get into this in a later tutorial,
    00:11:43,334but a lotta times they would be used, for example,
    00:11:45,967to parent the minute hand, hour hand, and clock,
    00:11:49,879to a Null,
    00:11:51,029so then now you can move the Null,
    00:11:52,939and it moves the entire clock.
    00:11:54,369So you don't have to move all three layers.
    00:11:57,139But what I'm gonna use it for here
    00:11:59,126is to add some controls for the clock.
    00:12:02,186So what I'm gonna do is rename this, Controls,
    00:12:07,466and what I wanna be able to control is the speed
    00:12:10,968that the clock is turning.
    00:12:13,254And I wanna be able to control the minute hand
    00:12:15,038and the hour hand with one control.
    00:12:17,705So with Expressions, this is pretty easy.
    00:12:20,520If you go up to the Effect menu,
    00:12:23,465you'll see this Expressions Controls area,
    00:12:26,368and if you never used Expressions,
    00:12:28,698you've probably never used these controls.
    00:12:31,070They are effects that on their own, don't do anything,
    00:12:34,195but you can use them to drive other layers
    00:12:37,266and other properties.
    00:12:38,628So what I'm gonna do is pick the Slider Control,
    00:12:42,643and you can go through and try out all of these controls,
    00:12:45,693and you'll be able to see what they look like,
    00:12:47,798and it may give you an idea
    00:12:48,933of what they could control for you.
    00:12:51,083The Slider Control just gives you one value
    00:12:53,768that you can change, and you can slide it,
    00:12:55,943or you can type in a number.
    00:12:58,631And this doesn't do anything on its own,
    00:13:00,621however it could drive something else.
    00:13:02,681So let's rename this Slider Control, Clock Speed.
    00:13:07,691So now
    00:13:10,565if we open up this layer,
    00:13:13,351go to Effects and go to Clock Speed,
    00:13:16,004and the hot key for that would be E,
    00:13:19,609and E brings up any Effects that are on a layer.
    00:13:23,399And we open up this arrow here,
    00:13:25,819so we can see the slider,
    00:13:27,549and the reason we need to do that is because
    00:13:29,846we are actually going to link
    00:13:31,609the speed of the minute hand to this slider.
    00:13:34,528So I'm gonna click the minute hand layer,
    00:13:36,166and I'm gonna hit U.
    00:13:37,648U is probably the most used hotkey in After Effects,
    00:13:40,678you should definitely know that one.
    00:13:42,198It opens up
    00:13:43,815any key frame
    00:13:47,582or properties that have Expressions on them.
    00:13:50,892So we can see our Expression on here,
    00:13:53,067and it says Time times 120,
    00:13:54,600so instead of hard coding the number 120
    00:13:58,199into this Expression,
    00:13:59,789I want this control to actually set what number
    00:14:03,229we're multiplying times by.
    00:14:06,289So what I'm gonna do is erase this,
    00:14:09,729and we're now gonna use the PickWhip button here.
    00:14:13,059This PickWhip button looks exactly like the one
    00:14:16,042in the parent column, and it works the same way.
    00:14:21,099The parent column let's you parent this layer
    00:14:23,137to this layer by just picking it and letting go.
    00:14:27,191So what we're gonna do is say we wanna multiply
    00:14:33,839make sure you use this PickWhip
    00:14:36,139in the Expression area,
    00:14:37,996and we're gonna PickWhip it to this slider.
    00:14:40,655And it doesn't work if you try to connect it
    00:14:42,427to the Effect itself,
    00:14:43,615it has to be to the value within that Effect.
    00:14:47,565And you can see that After Effects
    00:14:48,830automatically typed all this stuff in,
    00:14:50,627and this is basically saying Time times
    00:14:54,845this comp, meaning this Composition that we're in,
    00:14:58,435the layer named, Controls,
    00:15:01,714the Effect named Clock Speed
    00:15:06,039So you can see, it basically just starts very wide.
    00:15:09,684The entire comp,
    00:15:10,517and it gets narrower, and narrower, and narrower
    00:15:12,664until it's literally pointing to this exact Slider,
    00:15:15,944in this Effect, on this layer.
    00:15:18,797This is the way After Effects writes out
    00:15:22,684the address of this, if you will.
    00:15:24,954So we're gonna add the semi-colon,
    00:15:26,622hold Command and hit Return,
    00:15:29,404and the Slider's set to zero right now,
    00:15:31,454but let's say I set that back to 120.
    00:15:36,094So now the minute hand is moving again
    00:15:38,351at exactly one rotation every three seconds.
    00:15:41,234But if I change this to say, ten,
    00:15:44,214now it's moving very slowly.
    00:15:47,920So now, what's great about this is
    00:15:49,740I can basically copy this Expression,
    00:15:52,530I can just click in the box, and hit Command-C,
    00:15:55,580or CTRL-C on PC.
    00:15:58,390I'm gonna hit U on the hour hand.
    00:16:03,380I'm gonna erase this Expression
    00:16:04,790and paste the other Expression in there.
    00:16:07,300Now, we don't want the hour hand to move
    00:16:09,640the exact same speed as the minute hand, obviously.
    00:16:12,570We've decided we need it to move
    00:16:14,460twelve times less
    00:16:17,074than the minute hand.
    00:16:18,884So, what we're gonna do is have this Expression say
    00:16:23,764all of this stuff,
    00:16:24,746basically pointing to this Slider value,
    00:16:27,446and then we're going to divide by twelve.
    00:16:31,276So you can see you can have multiplication
    00:16:33,906and then division,
    00:16:35,236and you can basically type in a long string
    00:16:38,690that will sort of do all this math for you,
    00:16:41,421and arrive at the value,
    00:16:42,791and give you what you want.
    00:16:44,601So Command-Enter, and now you can see that
    00:16:49,197the hour hand
    00:16:50,224is moving at the right speed.
    00:16:52,336So here we are at twelve o' clock,
    00:16:54,556then the hand goes all the way around,
    00:16:55,704now we're at one o' clock.
    00:16:57,689Two o'clock.
    00:17:00,570the great thing is that now,
    00:17:02,510if we want the clock to go faster,
    00:17:05,385all we have to do is set this number to something else.
    00:17:08,909If we wanted it to go faster,
    00:17:10,279we could say 200,
    00:17:12,479and it will go faster,
    00:17:14,169but it will still work
    00:17:17,201the amount that the hour hand moves
    00:17:19,288relative to the minute hand will always stay correct because
    00:17:22,999we've set up the Expressions
    00:17:25,000to do that for us automatically.
    00:17:27,578So this is a very small example
    00:17:29,541of the power of Expressions,
    00:17:31,087but hopefully, it'll get your brain thinking
    00:17:34,477a little bit about ways to speed up your work by using this.
    00:17:39,457Again, if you were gonna key frame this
    00:17:41,867and have it be precise, it would be pretty tricky,
    00:17:45,357and then if your client came to you and said,
    00:17:47,637"Yeah, the clock looks great,
    00:17:48,897but can it go about 15% faster?"
    00:17:52,087Well that would be really tricky if you had key frames,
    00:17:54,927and you'd have to do some math,
    00:17:56,847and you'd have to do some trial and error.
    00:17:59,157And with this, all you would have to do is
    00:18:02,395change this number, change it to something else,
    00:18:04,560and now the clock goes slower or faster,
    00:18:07,191however you want it to work.
    00:18:09,206So that was the introduction to Expressions.
    00:18:11,986Hopefully, now you know how to apply Expressions,
    00:18:14,593you know how to look for Expressions in the dictionary,
    00:18:18,666and you know that you can always go up to Help,
    00:18:21,104and hit Expression Reference
    00:18:23,655and read about the Expressions there.
    00:18:25,793And I hope moving forward, this provides a foundation
    00:18:28,726you need to start using Expressions and After Effects.
    00:18:31,596Thank you guys so much, and I will see you guys soon.
    00:18:35,146- Thanks for watching.
    00:18:35,979I hope you learned a ton from this lesson,
    00:18:37,956and that you're now way more comfortable
    00:18:39,726with Expressions than when you started.
    00:18:41,466If you have any questions or thoughts, let us know,
    00:18:43,816and we would love to hear from you
    00:18:45,525if you use Expressions on a project.
    00:18:47,567So give us a shout on Twitter, @SchoolOfMotion
    00:18:50,305and show us your work.
    00:18:51,765And if you've learned something valuable
    00:18:52,955from this video, please share it around.
    00:18:55,015It really helps us spread the word
    00:18:56,493about School of Motion, and we truly, truly appreciate it.
    00:18:59,213Don't forget to sign up for a free student account
    00:19:01,597to access project files from the lesson you just watched,
    00:19:04,488plus a whole bunch of other awesome stuff.
    00:19:06,450Thanks again, and I'll see you next time.