Multi state badge: Step-by-step tutorial

Matt Perry
In this tutorial, we're going to build the Multi state badge example step-by-step.
This example is rated 3/5 difficulty, which means we assume you're already quite familiar with Motion (and JavaScript in general).
Here's a live demo of the example we're going to be creating:
Checking Motion+ status…
The Multi state badge tutorial
is exclusive to Motion+
290+ examples & 35+ tutorials
Premium APIs
Visual editor for VS Code
alpha
Discord community
Early access
Lifetime updates
One-time payment, lifetime updates
Already joined?
Introduction
The Multi-state Badge example shows how to create a component that smoothly animates between different states. This pattern is commonly used in UIs to provide visual feedback during form submissions, network requests, or any process with multiple stages.
In this tutorial, we'll learn to use:
motion
components for creating animatable elementsAnimatePresence
for coordinating the entrance and exit of componentsThe
animate
function for triggering imperative animationsuseTime
anduseTransform
motion value hooks for creating continuous animations
Using Motion for these animations offers significant advantages over standard CSS transitions. Motion handles the complex orchestration of multiple elements entering and exiting simultaneously, manages element measurement for dynamic content, and provides a declarative API for SVG path animations that would otherwise require complex JavaScript.