Enter animation: Step-by-step tutorial

Matt Perry
In this tutorial, we're going to build the Enter animation example step-by-step.
This tutorial is rated 1/5 difficulty, which means we'll spend some time explaining the Motion APIs that we've chosen to use (and why), and also any browser APIs we encounter that might be unfamiliar to beginners.
Here's a live demo of the example we're going to be creating:
Introduction
The Enter animation example shows how to animate an element when it first appears on the page. It uses the initial
and animate
props from Motion for React to create a smooth entrance effect.
CSS animations can only handle when elements appear, and even then only with the modern @starting-style
rule.
Get started
Let's start by creating a simple ball component without any animations:
This creates a blue circle on the page, but it just appears instantly without any animation.
Let's animate!
Import from Motion
To animate our ball, we first need to import the motion
component from Motion for React:
Basic functionality
Now we can replace the standard div
with a motion.div
:
To create an enter animation, we need to define:
An initial state for the element before animation starts
The final state we want it to animate to
We do this using the initial
and animate
props:
Customizing the animation
We can further customize how the animation behaves using the transition
prop:
This creates a pleasant bouncy effect as the ball appears, making it feel more lively and natural than a typical CSS easing curve.
Conclusion
In this tutorial, we learned how to:
Create enter animations using the
initial
andanimate
propsDefine different animation states using JavaScript objects
Customize animations with the
transition
propUse spring animations for more natural movement
Motion for React makes creating entrance animations straightforward, allowing you to add polish to your UI with minimal code.