logo
Course

Learn fromTo

Loading...

📘 So far, you learned:

  • — Animate
  • — Animate

But sometimes you don’t want GSAP to guess.

You want to say:

  • ✅ Start here
  • ✅ End here

That’s where comes in.


📖 What is .fromTo()?

lets you define both the starting and ending values manually.

This is super useful when:

  • You need exact control
  • You're chaining multiple animations
  • You don't want GSAP to "guess" starting or ending values
Sample image

Example: .fromTo() in Action

gsap.fromTo(
  ".box",
  {
    opacity: 0, // Start invisible
    y: 100, // Start 100px lower
  },
  {
    opacity: 1, // End fully visible
    y: 0, // End at normal position
    duration: 1,
  }
);

✅ The box fades in while moving from 100px below back to its normal position.

Code Playground

Result

👉 What happens here?

The box starts invisible and shifted down.

It animates to fully visible and back to normal position.

Clean. Predictable. Controlled.

Think of .fromTo() like setting a full GPS route: You choose both the starting point and the destination yourself. No automatic guessing — total precision.
Sample image

📚 .fromTo() Syntax Overview

gsap.fromTo(targets, fromVars, toVars);
Argument Meaning
targets What you want to animate (selector, element, object)
fromVars The starting values (ex: opacity: 0, y: 100)
toVars The ending values and options (ex: opacity: 1, duration: 1)

Tip:

  • Only put animatable properties inside fromVars
  • Put animation settings (like duration, ease, delay) inside toVars

🧪 Quick Practice Challenge

👉 Animate a .box to scale up and fade in using :

Code Playground

Result

Hint
monkey
gsap.fromTo(
  ".box",
  { opacity: 0, scale: 0 }, // Start tiny and invisible
  { opacity: 1, scale: 1, duration: 1 } // Grow and appear
);

✅ Why Use .fromTo()?

Without .fromTo() With .fromTo()
Might rely on CSS or current styles Full control of start and end
Potential surprises if styles change No surprises — you define both sides
Good for simple one-direction moves Great for choreographed, predictable animations

🔥 Coming Up Next...

You’ve now learned the three core tween types: , , and .

You're ready for the next big skill:

Stagger animations — animate multiple elements with beautiful delays between them!

Let’s animate armies of elements together in the next lesson! 🚀