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

gsap.to() - Animating To Values

Master the most common GSAP method to animate elements from their current state to target values.

gsap.to() - Animating To Values

You'll learn how to use GSAP's most fundamental method to smoothly animate elements from their current state to specified target values.

What is gsap.to()?

Think of gsap.to() like giving directions to a GPS: you don't tell it every turn along the way—you just specify the destination, and it figures out the smoothest route to get there. Similarly, gsap.to() takes your element from wherever it currently is and animates it to the values you specify.

This is the workhorse method of GSAP. You provide a target element (or elements) and an object containing the CSS properties you want to animate to, along with timing options.

Basic Syntax

gsap.to(target, {
  property: value,
  duration: seconds,
  // other options
});

Practical Examples

Animate a box to a new position and opacity:

gsap.to(".box", {
  x: 300,           // Move 300px right
  opacity: 0.5,     // Fade to 50% opacity
  duration: 1.5     // Animation takes 1.5 seconds
});

Animate multiple properties with easing:

gsap.to("#circle", {
  scale: 2,         // Double the size
  rotation: 360,    // Spin full circle
  backgroundColor: "#ff0000",
  duration: 2,
  ease: "power2.out"
});

The beauty of gsap.to() is that GSAP reads the element's current state automatically—you never need to specify starting values. If your element is already at x: 50, calling gsap.to() with x: 300 will animate the remaining 250 pixels.

Key Takeaway: gsap.to() is your primary GSAP animation method—specify your target element and desired end state, and GSAP handles the smooth interpolation from the current values to your targets.