Learn to create stunning web animations with GSAP - the industry-standard JavaScript library. Complete guide with code examples, performance.
Anand

Master the art of web animation with GreenSock Animation Platform (GSAP) - from basic tweens to advanced timeline animations that captivate users and boost engagement.
Table of Contents
GreenSock Animation Platform (GSAP) is the industry-standard JavaScript animation library trusted by over 11 million websites worldwide. Unlike CSS animations or other JavaScript libraries, GSAP offers unparalleled performance, cross-browser compatibility, and granular control over every aspect of your animations.
The fastest way to start using GSAP is through a CDN. Add this script tag to your HTML
The fastest way to start using GSAP is through a CDN. Add this script tag to your HTML:
html
<script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/gsap.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<style>
.box {
width: 100px;
height: 100px;
background: #3498db;
opacity: 0;
}
</style>
</head>
<body>
<div class="box"></div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/gsap.min.js"></script> <script>
gsap.to(".box", {duration: 2, opacity: 1, ease: "power2.out"});
</script>
</body>
</html>
GSAP provides four core tweening methods:
gsap.to() - Animate TO specified values:
gsap.to(".element", {x: 100, rotation: 360, duration: 2});
gsap.from() - Animate FROM specified values:
gsap.from(".element", {opacity: 0, y: -50, duration: 1});
gsap.fromTo() - Define both starting and ending values:
gsap.fromTo(".element",
{scale: 0, rotation: -180},
{scale: 1, rotation: 0, duration: 1.5}
);
GSAP makes CSS transforms simple and powerful:// Smooth, hardware-accelerated transforms
gsap.to(".card", {
x: 200, // translateX
y: 100, // translateY
rotation: 45, // rotate
scale: 1.5, // scale
skewX: 15, // skewX
transformOrigin: "center center",
duration: 2
});Easing brings life to animations. GSAP offers dozens of built-in easing functions:
// Smooth, natural easing
gsap.to(".element", {x: 300, duration: 2, ease: "power2.out"});
// Bouncy effect
gsap.to(".element", {y: 200, duration: 1.5, ease: "bounce.out"});
// Elastic animation
gsap.to(".element", {scale: 1.2, duration: 1, ease: "elastic.out(1, 0.5)"});Timelines are GSAP's secret weapon for creating complex, sequenced animations:
see this url for understanding it better
- https://gsap.com/docs/v3/GSAP/
const tl = gsap.timeline();
tl.from(".header", {y: -100, opacity: 0, duration: 1})
.from(".content", {x: -200, opacity: 0, duration: 0.8}, "-=0.3")
.from(".button", {scale: 0, duration: 0.5, ease: "back.out(1.7)"}, "-=0.2");Create scroll-based animations that respond to user interaction:
gsap.registerPlugin(ScrollTrigger);
gsap.to(".parallax-element", {
y: -200,
ease: "none",
scrollTrigger: {
trigger: ".parallax-element",
start: "top bottom",
end: "bottom top",
scrub: true
}
});Transform SVG shapes seamlessly:
gsap.to("#morphShape", {
duration: 2,
attr: { d: "M0,0 L100,50 L50,100 Z" },
ease: "power2.inOut"
});GSAP transforms static web experiences into dynamic, engaging interfaces that captivate users and drive conversions. By mastering the techniques covered in this guide—from basic tweens to advanced timeline management—you'll be equipped to create professional-grade animations that perform flawlessly across all devices and browsers.
Remember these key takeaways:
The web animation landscape continues to evolve, and GSAP remains at the forefront, providing developers with the tools needed to create tomorrow's most compelling digital experiences.
Ready to start animating? Download GSAP today and transform your static designs into dynamic, user-engaging experiences that stand out in today's competitive digital landscape.
Passionate about creating amazing web experiences and sharing knowledge with the developer community.
Discover more insightful articles and tutorials to expand your knowledge
No related articles found at the moment.
Browse All Articles