Animation can make an interface feel alive, or it can make it feel slow. The difference rarely comes from the tool. It comes from why something moves, how long it takes, and what it costs the browser to do it.
This article starts with principles that apply to any library, then looks at the two tools many frontend teams reach for: GSAP, a mature general-purpose animation engine, and Motion, a modern library that spans plain JavaScript and React.
Why Animate at All?
Good motion has a job. It should do at least one of these:
- Explain change. A panel that slides in shows where it came from and where it goes.
- Give feedback. A button that responds to a press confirms the action was received.
- Direct attention. A subtle entrance pulls the eye to what matters first.
- Create continuity. Shared transitions help users keep their place between states.
If an animation does none of these, it is decoration, and decoration has a cost. Every effect competes for the main thread and for the user's patience.
Principles That Apply Everywhere
Animate cheap properties
The browser can animate transform and opacity on the compositor, without recalculating layout or repainting. Animating width, height, top, or margin forces layout work on every frame.
Keep timing short and purposeful
Most interface transitions feel right between roughly 150 and 400 milliseconds. Longer durations are for large, expressive moments such as a page entrance. Short and snappy beats long and floaty for anything the user triggers.
Choose easing deliberately
Linear motion looks mechanical. Natural movement accelerates and decelerates. Elements entering the screen usually ease out (fast, then slow), while elements leaving ease in. Springs add a physical feel without needing hand-tuned curves.
Respect reduced motion
Some people experience discomfort or nausea from large movement. Operating systems expose a preference, and your code should honor it:
In JavaScript, check window.matchMedia('(prefers-reduced-motion: reduce)') and skip or simplify the animation.
Start With CSS
Before reaching for a library, consider whether CSS is enough. Transitions and keyframes cover hover states, simple entrances, loaders, and many micro-interactions with no JavaScript at all, and the browser optimizes them well.
Libraries earn their place when you need sequencing, scroll-linked behavior, physics, dynamic values at runtime, or coordination across many elements.
GSAP: The Animation Engine
GSAP is a JavaScript animation platform that has been a standard for creative web work for many years. It animates almost anything, CSS properties, SVG attributes, canvas values, and plain objects, and it smooths over browser inconsistencies.
Tweens and timelines
The core unit is a tween. A timeline chains tweens into a sequence you can position precisely:
The position parameter, such as '-=0.4', is what makes timelines easy to tune: you adjust relative timing without recalculating absolute delays.
Stagger
Animating many elements with a small offset between each is a single option:
ScrollTrigger connects animation to scrolling. It can start an animation when an element enters the viewport, scrub an animation with the scroll position, or pin a section while its content animates:
Cleaning up
Animations that outlive their elements cause leaks and strange behavior, especially with client-side navigation. Group them in a context and revert it when the component or page goes away:
GSAP also ships a React hook for the same purpose. Its plugins have become available without a paid license for most uses, so check the current license terms for your project.
Motion: Declarative and Spring-Based
Motion is the library formerly known as Framer Motion, now published as the motion package. It offers a small, modern API in plain JavaScript and a component-based API for React.
The vanilla animate function
Where possible, Motion hands work to the browser's Web Animations API, which allows hardware-accelerated animation with a small amount of code.
React components
In React, Motion turns animation into props. State changes drive the animation, so you describe the target rather than orchestrating steps:
Two features stand out in React:
AnimatePresence lets elements animate out before they are removed from the tree, something that is awkward to do by hand.
layout animations smooth changes in size and position, such as reordering a list, without manual measurement.
GSAP and Motion Compared
| Need |
GSAP |
Motion |
| Long, choreographed sequences |
Excellent: timelines with position control |
Possible, less central |
| Scroll-driven storytelling and pinning |
Excellent: ScrollTrigger |
Good for linking values to scroll |
| React state-driven UI animation |
Workable with hooks |
Excellent: props, presence, layout |
| Springs and gestures |
Available |
Built in and a core strength |
| Animating SVG, canvas, or arbitrary objects |
Excellent |
Good |
| Bundle footprint |
Larger, modular by plugin |
Small for the vanilla API |
Choosing Between Them
There is no single winner. A few rules of thumb:
- Mostly CSS-able effects? Use CSS and skip the library.
- Interactive React interface with mounting, unmounting, and layout changes? Motion fits naturally.
- Marketing or portfolio pages with long sequences and scroll-driven sections? GSAP with ScrollTrigger is hard to beat.
- A mix? Many projects use both: Motion for small interface transitions, GSAP for the page-level storytelling. They do not conflict as long as they animate different elements.
A Reusable Entrance Pattern
Whatever the tool, a clean entrance follows the same recipe: set a hidden starting state, animate to the final state, and honor reduced motion.
- Animate
transform and opacity, not layout properties.
- Apply
will-change sparingly, only to elements that are about to animate, and remove it afterward.
- Avoid animating many large, blurred, or filtered elements at once; they are expensive to paint.
- Pause what is off-screen. Stop loops and observers for elements the user cannot see.
- Clean up on page change or unmount to avoid leaks and duplicate listeners.
- Test on a modest device. An animation that is smooth on a developer laptop may stutter on a phone.
Takeaway
Motion should explain, confirm, or guide, never just fill space. Start with CSS, move to a library when the job needs sequencing, scroll linkage, or physics, and choose GSAP or Motion according to the shape of the work rather than habit. Keep animations on cheap properties, honor reduced motion, and clean up after yourself, and the result will feel polished on every device.
Comments
Join the conversation
Sign in with GitHub to leave a comment on Web Animation in Practice: Principles, GSAP, and Motion.