Course contentsShow
← Web Development
Lesson 2549 of 2,98246. Animation LibrariesFree lesson

gsap.from() and gsap.fromTo()

Learn to animate elements from specified start values or define both start and end states.

gsap.from() and gsap.fromTo()

You'll learn how to animate elements from a starting position or define both the beginning and end states of an animation.

Understanding the Core Difference

While gsap.to() animates toward target values, gsap.from() animates from specified values to the element's current state. Think of it like this: gsap.to() is telling an element "go there," while gsap.from() says "you just came from there—show me the journey."

The gsap.fromTo() method gives you complete control by defining both starting and ending values explicitly.

Using gsap.from()

gsap.from() sets temporary starting values and animates to the element's natural state:

// Element fades in and slides down from above
gsap.from(".box", {
  opacity: 0,
  y: -100,
  duration: 1
});

The element appears to start at opacity: 0 and y: -100, then animates to its actual CSS values (full opacity, natural position).

Using gsap.fromTo()

When you need surgical precision over both states, use gsap.fromTo() with two configuration objects:

// Explicitly define start AND end states
gsap.fromTo(".box", 
  { opacity: 0, scale: 0.5 },  // FROM these values
  { opacity: 1, scale: 1.2, duration: 1 }  // TO these values
);

This is particularly useful when the element's current CSS state isn't what you want as either endpoint.

When to Use Which

Use gsap.from() for entrance animations where elements should end in their natural state. Use gsap.fromTo() when you need complete control over both the start and finish, regardless of existing styles.

Key Takeaway: gsap.from() animates from specified values to current state, while gsap.fromTo() lets you define both starting and ending values for complete animation control.