GreenSock (GSAP) handles animation on both DOM elements and in WebGL, Canvas, or Three.js contexts. Its easing model goes beyond CSS, which is limited to two bezier handles and needs stacked keyframes to fake a bounce; GSAP permits multiple handles, so a bounce is a single line of code. Movement can be sequenced on a timeline, which stays legible where coordinating several CSS animations turns into spaghetti, and the timeline itself can be animated. The library also runs calculations under the hood to normalize cross-browser quirks and stacking-transform behavior, and offers plugins for morphing and drawing SVG, drag-and-drop, inertia, and more.
Animating a DOM element
A ball built from a <div> with border-radius: 50% is scaled and moved as follows:
<div class="ball"></div>
gsap.to('.ball', {
duration: 1,
x: 200,
scale: 2
})
gsap takes the .ball element and drives properties with .to(). CSS transforms are shortened: transform: translateX(200px) becomes x: 200, with units optional but accepted as a string, and transform: scale(2) becomes scale. Common transform properties and their CSS equivalents:
x: 100 // transform: translateX(100px)
y: 100 // transform: translateY(100px)
z: 100 // transform: translateZ(100px)
// you do not need the null transform hack or hardware acceleration, it comes baked in with
// force3d:true. If you want to unset this, force3d:false
scale: 2 // transform: scale(2)
scaleX: 2 // transform: scaleX(2)
scaleY: 2 // transform: scaleY(2)
scaleZ: 2 // transform: scaleZ(2)
skew: 15 // transform: skew(15deg)
skewX: 15 // transform: skewX(15deg)
skewY: 15 // transform: skewY(15deg)
rotation: 180 // transform: rotate(180deg)
rotationX: 180 // transform: rotateX(180deg)
rotationY: 180 // transform: rotateY(180deg)
rotationZ: 180 // transform: rotateZ(180deg)
perspective: 1000 // transform: perspective(1000px)
transformOrigin: '50% 50%' // transform-origin: 50% 50%
Duration is a one-second stretch of time.
SVG targets
Turn the same example into SVG and the animation code is exactly the same — it still grabs the element with class .ball and translates those properties. SVGs are DOM elements, so a class on any of them animates the same way.
<svg viewBox="0 0 500 400">
<circle class="ball" cx="80" cy="80" r="80" />
</svg>
gsap.to('.ball', {
duration: 1,
x: 200,
scale: 2
})
Easing
A bounce on the original ball takes one addition:
gsap.to('.ball', {
duration: 1.5,
x: 200,
scale: 2,
ease: 'bounce'
})
GSAP assumes ease-out timing by default (good for entrances); naming "bounce" as a string overrides it. The duration is lengthened too, since the ball does more work between states: one second works for linear or sine easing but is too quick for bounce or elastic.
Delays, timelines and defaults
For exits, use an ease-in or ease-in-out. Note the second-to-last line prefers ease: 'back.inOut(3)' over bounce.in: back provides the ease-in-out, and the argument adjusts its configuration, as GSAP's ease visualizer shows. The animations are chained by matching the delay to the first animation's duration — brittle, since changing the duration means recalculating every delay downstream, and complex animations can chain hundreds of steps. Enter timelines:
gsap
.timeline()
.to('.ball', {
duration: 1.5,
x: 200,
scale: 2,
ease: "bounce"
})
.to('.ball', {
duration: 1.5,
x: 0,
scale: 1,
ease: "back.inOut(3)"
});
This instantiates a timeline and chains both animations off it. Repeated durations can then become a timeline default:
gsap
.timeline({
defaults: {
duration: 1.5
}
})
.to('.ball', {
x: 200,
scale: 2,
ease: "bounce"
})
.to('.ball', {
x: 0,
scale: 1,
ease: "back.inOut(3)"
});
Defaults and timelines keep genuinely complex animations maintainable.
Loops and yoyos
To keep the motion going, add repeat: -1, either to a single animation or the whole timeline.
gsap
.timeline({
repeat: -1,
defaults: {
duration: 1.5
}
})
.to('.ball', {
x: 200,
scale: 2,
ease: "bounce"
})
.to('.ball', {
x: 0,
scale: 1,
ease: "back.inOut(3)"
})
.to('.ball', {
x: -200,
scale: 2,
ease: "bounce"
})
.to('.ball', {
x: 0,
scale: 1,
ease: "back.inOut(3)"
});
For back-and-forth playback, yoyo: true. Shown here with just the first animation, it plays forward and then in reverse:
gsap
.timeline({
repeat: -1,
yoyo: true,
defaults: {
duration: 1.5
}
})
.to('.ball', {
x: 200,
scale: 2,
ease: "bounce"
})
Overlaps and labels
Chained animations are sequential, but real motion is continuous — walking to a glass of water doesn't stop between each step. Three balls animated one after another feel stiff:
gsap
.timeline({
defaults: {
duration: 1.5
}
})
.to('.ball', {
x: 300,
scale: 2,
ease: "bounce"
})
.to('.ball2', {
x: 300,
scale: 2,
ease: "bounce"
})
.to('.ball3', {
x: 300,
scale: 2,
ease: "bounce"
})
Overlapping them slightly with decrementers passed as strings smooths it out:
gsap
.timeline({
defaults: {
duration: 1.5
}
})
.to('.ball', {
x: 300,
scale: 2,
ease: "bounce"
})
.to('.ball2', {
x: 300,
scale: 2,
ease: "bounce"
}, '-=1')
.to('.ball3', {
x: 300,
scale: 2,
ease: "bounce"
}, '-=1')
Labels fire things at a particular point in the playhead: .add('labelName').
gsap
.timeline({
defaults: {
duration: 1.5
}
})
.add('start')
.to('.ball', {
x: 300,
scale: 2,
ease: "bounce"
}, 'start')
.to('.ball2', {
x: 300,
scale: 2,
ease: "bounce"
}, 'start')
.to('.ball3', {
x: 300,
scale: 2,
ease: "bounce"
}, 'start')
Labels can be incremented and decremented too — 'start+=0.25' — which is a frequent pattern:
gsap
.timeline({
defaults: {
duration: 1.5
}
})
.add('start')
.to('.ball', {
x: 300,
scale: 2,
ease: "bounce"
}, 'start')
.to('.ball2', {
x: 300,
scale: 2,
ease: "bounce"
}, 'start+=0.25')
.to('.ball3', {
x: 300,
scale: 2,
ease: "bounce"
}, 'start+=0.5')
Staggers, morphing and drawing SVG, throwing elements around the screen, motion paths, and text animation are not covered here; GreenSock's documentation details those.



