✨ Getting Started with GSAP: A Beginner's Guide to GSAPFrom, GSAPTo, Timeline & More

Forhad HossainForhad Hossain
3 min read

Today, I took my first deep dive into the world of animations with GSAP (GreenSock Animation Platform)—a powerful JavaScript animation library used by professional developers and designers to create stunning animations with smooth performance. In this post, I’ll walk you through the GSAP fundamentals I explored: gsap.from(), gsap.to(), gsap.fromTo(), gsap.timeline(), ScrollTrigger, and gsap-text.


💡 What is GSAP?

GSAP is a robust, high-performance JavaScript library that lets you animate anything on the web—HTML elements, CSS properties, SVG, canvas, and more. It's known for its precise timing, flexible API, and ease of use.


🔁 gsap.from()

The gsap.from() method animates an element from a certain state to its current (default) position or appearance.

gsap.from(".box", {
  x: -200,
  opacity: 0,
  duration: 1
});

This means: the box will animate from -200px on the X-axis and 0 opacity to its original position and full visibility.


🔄 gsap.to()

The gsap.to() method animates an element from its current state to a specified final state.

gsap.to(".box", {
  x: 200,
  opacity: 1,
  duration: 1
});

This means: the box will move 200px to the right and become fully visible.


🔁 gsap.fromTo()

The gsap.fromTo() method is like combining both from() and to() into one. It defines both the starting and ending values.

gsap.fromTo(".box",
  { x: -100, opacity: 0 },
  { x: 100, opacity: 1, duration: 1 }
);

This means: the box starts at -100px and invisible, then moves to 100px and becomes visible.


🧵 gsap.timeline()

The gsap.timeline() helps you create sequenced animations. It's perfect when you want animations to play one after another, or in overlapping time.

const tl = gsap.timeline();

tl.from(".title", { y: -50, opacity: 0, duration: 0.5 })
  .from(".subtitle", { y: -30, opacity: 0, duration: 0.5 }, "-=0.3")
  .to(".button", { scale: 1.1, duration: 0.3 });

This means: title and subtitle animate in sequence, and the button pops in after that.


🖱️ ScrollTrigger (plugin)

ScrollTrigger allows you to trigger animations when elements come into view during scrolling. It's part of the GSAP plugin ecosystem.

gsap.from(".section", {
  scrollTrigger: ".section",
  y: 100,
  opacity: 0,
  duration: 1
});

This means: when the .section element scrolls into view, it will animate upward and fade in.

✅ Don't forget to register the plugin:

import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);

✍️ gsap-text (TextPlugin)

GSAP TextPlugin is useful when you want to animate text like a typewriter effect.

gsap.to(".text", {
  text: "Hello GSAP World!",
  duration: 2,
  ease: "none"
});

✅ Also register this plugin:

import { TextPlugin } from "gsap/TextPlugin";
gsap.registerPlugin(TextPlugin);

✅ Final Thoughts

Learning GSAP fundamentals was exciting! Here's a quick recap of what I learned today:

  • 🎬 gsap.from() – animate from a start state.

  • 🎬 gsap.to() – animate to an end state.

  • 🎬 gsap.fromTo() – define both start and end states.

  • 🧵 gsap.timeline() – chain animations in a sequence.

  • 🖱️ ScrollTrigger – animate elements as they enter the viewport.

  • ✍️ TextPlugin – animate text content.

Whether you want to add subtle effects or go full cinematic, GSAP gives you the tools to bring your UI to life.


Happy Animating! 🚀
If you're just starting like me, don’t be afraid to play around with different values and elements. That’s the best way to learn!

0
Subscribe to my newsletter

Read articles from Forhad Hossain directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Forhad Hossain
Forhad Hossain

Hi, I'm Farhad Hossain, a passionate web developer on a journey to build impactful software and solve real-world problems. I share coding tips, tutorials, and my growth experiences to inspire others.