
Learn how to create smooth movements, control timing, and build interactive experiences with GSAP.
Introduction
This GSAP tutorial walks beginners through the essentials — from your first tween to full animation timelines — using the GreenSock Animation Platform (GSAP), one of the most widely used animation libraries for the web. The GreenSock Animation Platform (GSAP) is a feature-rich animation library that allows developers to create dynamic effects in web apps, games, and interactive stories. With GSAP, anything can be animated on the browser.
Getting started with GSAP can be an exciting venture into the world of web animations. Renowned for its performance and flexibility, GSAP powers animations on numerous high-profile sites. However, beginners might find the vast features and capabilities of GSAP a bit daunting. Here's a guide to help you start your animation journey with GSAP smoothly, addressing common challenges and offering effective solutions.
Understanding GSAP's Rich Ecosystem
This GSAP tutorial starts with the core building blocks: the main classes and plugins, which together offer over a hundred methods to create, inspect, and control animations. For a beginner, this can seem overwhelming. Focus initially on the core functionalities:
- TweenLite: A lightweight version of TweenMax, perfect for simple animations.
- TweenMax: Includes more features and plugins.
- TimelineLite: Helps in sequencing multiple animations.
- TimelineMax: An extended version of TimelineLite with additional features.
Use the official GSAP documentation to understand what each class and method does.
Start Small and Simple
A common mistake is to dive into complex projects too early. Beginners often envision integrating advanced animations with elements like ScrollMagic, SVGs, or 3D effects right away. Begin with basic animations, try simple tasks like animating a box moving across the screen or fading in an element. These small projects are easier to manage and debug. For instance, animating a single DOM element’s opacity or position can teach you a lot about how GSAP handles timing and easing.
Use Available Learning Resources
GSAP offers a variety of learning materials tailored for beginners, including a Getting Started guide, introductory videos, and the Jump Start tutorial. Make full use of these resources. The Getting Started video is particularly helpful in visualizing how GSAP works. Also, platforms like CodePen are invaluable for exploring existing projects and practicing your skills by modifying those projects.
Starting with GSAP Coding
Installing GSAP
Once you're ready to start coding, this GSAP tutorial covers the two most common setups: loading GSAP from a CDN, or installing it via npm for React and other JS frameworks. To load GSAP into your page, use the following script tag:
Creating Tweens
Tweens are the basis for creating animations in GSAP. We set the properties we want to animate, the duration of the animation, the animation's easing, and other properties like delay using tweens. There are three common methods for creating a Tween:
- gsap.to()
- gsap.from()
- gsap.fromTo()
Example
HTML:
CSS:
.box {
width: 50px;
height: 50px;
margin-top: 20px;
background: tomato;
}
gsap.to()
When using this method, GSAP automatically sets the initial values based on the set CSS properties of the given element.
```javascript
gsap.to(".box", {
borderRadius: 50,
x: 100,
scale: 1.5,
duration: 1
});
```
gsap.from()
The from() method is best used for reverse animation. When you set the initial CSS properties, GSAP will animate to the default values.
```javascript
gsap.from(".box", {
y: 80,
opacity: 0,
duration: 2
});
```
gsap.fromTo()
With the fromTo() method, developers can define both the start and end properties of a given animation.
```javascript
gsap.fromTo(".box", {
x: 20,
borderRadius: 10
}, {
x: 80,
borderRadius: 50,
duration: 1
});
```
Creating Timelines
To achieve a more concise animation, where you define exactly which animation comes first, you can chain the to() method and list the animations (tweens) in the order that you want them. First, create a timeline:
var tl = gsap.timeline({repeat: 30, repeatDelay: 1});
Then, add each of your tweens to the already created timeline:
```javascript
tl.add(gsap.to("#box", {duration: 1, x: 100}));
tl.add(gsap.to("#box2", {duration: 2, x: 100, scale: 1.1}));
tl.add(gsap.to("#box3", {duration: 3, x: 100, scale: 2}));
```
Basic GSAP Example:
Part 1: Basic GSAP Code
In the first example, we use GSAP to animate elements individually with specific properties like duration, delay, translation (x and y), easing, and staggering. Here is the basic code:
https://codesandbox.io/p/devbox/wx658g?file=%2Findex.html
// Basic GSAP Animations
gsap.from('.header', { duration: 1, y: '-100%', ease: 'bounce' });
gsap.from('.link', { duration: 1, opacity: 0, delay: 1, stagger: 0.5 });
gsap.from('.right', { duration: 1, x: '-100vw', delay: 1, ease: 'power2.in' });
gsap.from('.left', { duration: 1, delay: 1.5, x: '-100%' });
gsap.to('.footer', { duration: 1, y: 0, ease: 'elastic', delay: 2.5 });
gsap.fromTo('.button', { opacity: 0, scale: 0, rotation: 720 }, { duration: 1, delay: 3.5, opacity: 1, scale: 1, rotation: 0 });
Explanation
- Staggering: Allows animating a group of elements with delays between each animation, creating a sequential or overlapping effect.
- Duration: Defines the time an animation takes to complete.
- TranslateY (y) and TranslateX (x): Move the element along the Y-axis and X-axis respectively.
- Ease: Specifies the speed curve of the animation.
- Delay: Adds a start time for the next animation.
In this example, each animation has a delay to ensure they start one after another. For instance, if we set a duration of 2 seconds for an animation, we must add a 2-second delay to the next animation; otherwise, the second animation will start before the first one is completed. Manually adding delays, however, is not efficient for longer sequences.
Part 2: Using Timelines
Timelines allow you to chain animations together, making it easier to control the sequence and timing without manually adding delays.
// Using GSAP Timelines
const timeline = gsap.timeline({ defaults: { duration: 1 } });
timeline
.from(".header", { y: "-100%", ease: "bounce" })
.from(".link", { opacity: 0, stagger: 0.5 })
.from(".right", { x: "-100vw", ease: "power2.in" }, 1)
.from(".left", { x: "-100%" }, "<-2")
.to(".footer", { y: 0, ease: "elastic" })
.fromTo(
".button",
{ opacity: 0, scale: 0, rotation: 720 },
{ opacity: 1, scale: 1, rotation: 0 }
);
const button = document.querySelector(".button");
button.addEventListener("click", () => {
timeline.timeScale(3); // 3 times faster
timeline.reverse();
});
Explanation
- Timeline Defaults: Sets default properties (like duration) for all animations in the timeline.
- Chaining Animations: Allows for a seamless sequence of animations without manually setting delays.
- Ease and Stagger: Remain effective, providing smooth and dynamic animation flows.
- Control Animations: By adding event listeners, you can control the timeline's playback, such as speeding up or reversing the animations.
Some more examples:
1) Scroll trigger - https://codesandbox.io/p/devbox/scroll-trigger-h4qqyy
2) Scroll To - https://codesandbox.io/p/devbox/scroll-to-y68hym
Using GSAP Plugins
To use GSAP plugins like ScrollTrigger, TextPlugin, etc., you must first register those plugins in your JS file or script tag.
gsap.registerPlugin(ScrollTrigger, TextPlugin);
To see basic ScrollTrigger animation you can see the example in below links:
https://www.youtube.com/watch?v=X7IBa7vZjmo&t=614s
Using GSAP in React
To use GSAP in React, first install it using the command:
npm i gsap
Initially, you had to use `useEffect` and `useRef` for GSAP animations, but now GSAP has introduced its own hook called `useGSAP`, which handles animation and its cleanup, so you don’t have to do it manually like before. Use the official GSAP documentation (https://gsap.com/docs/v3/GSAP/Tween/) to understand more about GSAP with react. https://gsap.com/resources/react-basics/
Learn from Mistakes
A common mistake beginners make with any GSAP tutorial is copying and pasting code from other projects instead of typing it out themselves. However, this approach can limit deeper learning opportunities provided by troubleshooting errors. Type out the code yourself. This practice helps familiarize you with GSAP’s syntax and nuances. When errors occur—missing a comma or a semicolon, or forgetting to close curly braces—fixing them teaches you about the structure and requirements of the code, which is invaluable for mastering GSAP.
Conclusion
This GSAP tutorial shows that getting started doesn't have to be intimidating — approach it step by step, and you'll be animating confidently in no time. Focus on learning the basics well, leverage the abundant resources available, and engage in practical, hands-on projects. By understanding the common pitfalls and how to navigate them, you’ll find that GSAP is an immensely powerful tool in your web development arsenal, capable of bringing any webpage to life with captivating animations

Sanyam Sharma
Put AI to work in your content engine
We design AI-native marketing workflows that ship - not demos.
Keep reading
View more →_desktop_list_webp_d12ff3cb.webp&w=3840&q=75)
How Much Does AI Website Development Cost in India 2026 Real Numbers | Every Feature Priced

How to Build an AI-Powered E-commerce Store in India : What Actually Increases Sales (2026 Guide)

AI Chatbot for Your Website & WhatsApp:The Complete Buying Guide for Indian Businesses (2026)
Get the good stuff, monthly.
One thoughtful email a month - new research, playbooks, and ideas. No noise.