- Master Sequencing: Use the `gsap.timeline()` method to precisely control the order and timing of multiple animations.
- Orchestrate Complexity: Combine standard tweens with timeline methods like `stagger` and overlap markers to build intricate motion stories.
- Advanced Control: Leverage advanced features like nested timelines and custom iteration to manage complex, state-based animations.
Understanding GSAP Timelines: Why Sequencing Matters
Animation is rarely a single action. Most web experiences require multiple elements to animate in a specific order, or for several elements to coordinate their movements. This is where the GSAP timeline comes in. A timeline is essentially a container that holds and organizes multiple animations, or "tweens."
If you simply call multiple animation methods sequentially, they might execute simultaneously or unpredictably. The timeline solves this. It provides a single, cohesive timeline axis upon which you can plot every animation. This deterministic approach is crucial for building reliable, complex interactions. Mastering the timeline is the core skill required to build GSAP animation that feels choreographed rather than random.
The Core Building Blocks: Initializing Timelines and Basic Tweens (from(), to())
Before diving into sequencing, remember the fundamentals of GSAP. The basic unit of animation is the tween. Tweens animate properties of an element over time. You can set the starting state and the ending state.
Use the `gsap.to()` method for simple animations, which transitions an element from its current state to a new end state. For more control, use `gsap.from()` to animate an element into view from a defined starting point. Both methods work within the timeline structure.
A simple workflow involves selecting the target element, defining the properties to change (like `opacity` or `x` position), and then adding that tween to a timeline instance.
Mastering Animation Flow: Sequencing, Staggering, and Overlap
The real power of the timeline emerges when you control the timing relationships between tweens. The timeline object allows you to manage three key concepts: sequencing, staggering, and overlap.
Sequencing
Sequencing means forcing animations to play one after the other. You add the first animation to the timeline, then add the second, and so on. The second animation will not start until the first one has completed, ensuring a clear, directional flow. This is fundamental to any gsap animation basics tutorial.
Staggering
Staggering is used when you want a group of elements to animate in sequence, but not necessarily one after the other. For example, animating a list of five items. Instead of animating all five at once, you can stagger them so that they appear with a slight, rhythmic delay. The timeline accepts a stagger parameter, automating this delay calculation across a defined collection of targets.
Overlap
Sometimes, animations must run concurrently. Overlapping allows you to place multiple tweens on the timeline at the same time marker. This is ideal for creating complex, overlapping effects, such as an element scaling up while simultaneously changing its color. You simply pass the animation calls to the timeline without waiting for completion.
Advanced Techniques: Easing, Iteration, and Creating Complex Motion Stories
To make your animations feel professional, you must manage timing and motion curves. Easing controls the acceleration and deceleration of an animation. Instead of a linear speed, easing functions (like `power1.inOut()`) create natural, physical motion, making the movement feel weighty and smooth.
For highly dynamic or data-driven animations, use the timeline to manage iteration. You can loop animations or run a sequence of animations based on a counter or state change. By combining staggered tweens with timeline markers, you can create sophisticated, non-linear motion stories. This mastery takes the process from simple animation to true motion design.
How do I make sure animations run in order?
Always use the timeline structure. By adding animations sequentially to the timeline, you enforce a strict, predictable order of execution, ensuring the second animation waits for the first to finish.
Is there a difference between `gsap.to()` and `timeline.add()`?
Yes. `gsap.to()` creates a standalone tween. The timeline method, `timeline.add()`, places that tween into the coordinated sequence, allowing you to control its exact start time relative to other elements on the timeline.
Should I use CSS transitions or GSAP for complex sequences?
For simple, single-state changes, CSS transitions are efficient. However, for coordinating multiple properties, managing complex timing, or creating responsive, state-driven motion sequences, GSAP provides the necessary control and performance.
Ready to turn your animation into a video?
Animation Machine converts Claude Design, Lottie, GSAP, and CSS animations to MP4 or GIF in seconds. Unlimited renders, background music, 1080p output.
Get started — $5/month