graphicsmotion

gsap

tweens, timelines, easing, stagger, scroll, svg, flip and split text, with a live demo of each.

report a mistake
.md

a tween changes values over time. a timeline lines tweens up. scroll, svg, layout and text are plugins on top.

duration
0.5 s the default, when you leave it out
ease
power1.out the default. quick start, soft stop
plugins
free all of them, since 3.13
from()
at once sets its start values the moment it's made
reach for it
  • a sequence of ui motion
  • scroll-driven effects
  • svg strokes and shapes
  • layout changes, with flip
on this page
  1. tween
  2. timeline
  3. easing
  4. stagger
  5. scrolltrigger
  6. svg draw
  7. svg morph
  8. flip
  9. split text
  10. pitfalls
  11. sources

gsap is a javascript animation library. you name a target and the values it should reach, and gsap moves them there over time, one step per animation frame, in step with the browser.1 this sheet is the core (tween, timeline, ease, stagger) and five plugins. every figure waits for you: a press, a scroll or a drag. nothing moves on its own.

this page runs gsap 3.15.0. since 3.13 the whole library is free, plugins included, for commercial work too.2 the license is the standard “no charge” one: any site or app, paid work included. what it rules out is building gsap into a no-code animation tool that competes with webflow, which owns gsap.3

tween

a tween animates properties of a target from where they are to the values you give. gsap.to is the usual one. gsap.from runs the other way: it starts at the values you give and ends where the target already is. gsap.fromTo spells out both ends. gsap.set is a tween with no duration: the values, now. the target can be an element, a selector string, an array, or a plain object.45

leave duration out and it is 0.5 s. leave ease out and it is power1.out. gsap.defaults changes both for every tween made after it.46

import { gsap } from 'gsap';

gsap.to('.box', { x: 200, duration: 1, ease: 'power2.out' }); // from where it is to x: 200
gsap.from('.box', { opacity: 0, y: 20 }); // starts there, ends where it already is
gsap.fromTo('.box', { x: 100 }, { x: 200, duration: 0.8 }); // both ends spelled out
gsap.set('.box', { x: 200 }); // no animation: the values, now

const tween = gsap.to('.box', { x: 200, paused: true }); // make it once, drive it later
tween.play();
tween.reverse();
tween.progress(0.5);

for css transforms, use the shorthands: x and y are a translate in px, xPercent and yPercent a translate in percent of the element’s own size, rotation in degrees, scale. gsap applies them in one fixed order, and it skips the parsing a transform string would need. autoAlpha is opacity and visibility together, so a faded-out thing also stops taking clicks.7

gsap.to(box, { x: 200 })

from where it is to the value. 0.5 s and power1.out: the defaults, since the call doesn't set them.

one white square on a dashed track and four buttons: to, from, fromTo and set. each button runs that gsap call on the square with the default duration and ease. a dashed cyan outline marks where the square starts and an amber one where it ends, a thin bar under the track fills with the tween's progress, and a line of code shows the call that ran. a replay button runs it again.

from jumps to the far end first, then comes back. that first jump happens before the first frame.

a tween is an object you keep: play, pause, reverse, restart, progress(0.5), timeScale(2), kill.8 a timeline has the same controls.

what trips people up:

timeline

gsap.timeline() lines tweens up. each .to() on it goes at the end of the timeline, unless the third argument, the position parameter, says otherwise. the timeline’s defaults go into every tween it makes, and a tween’s own vars win. the whole thing plays, pauses, reverses, scrubs and changes speed as one.1213

const tl = gsap.timeline({ defaults: { duration: 0.8, ease: 'power2.inOut' }, paused: true });
tl.to('.a', { x: 200 }) // at 0
  .to('.b', { x: 200 }, '<') // with the start of the previous tween
  .to('.c', { x: 200 }, '-=0.3') // 0.3 s before the end of the timeline: an overlap
  .addLabel('out')
  .to('.a', { opacity: 0 }, 'out+=0.5'); // half a second after the label

tl.play();
tl.reverse();
tl.progress(0.5); // scrub to the middle
tl.timeScale(2); // twice as fast

the position parameter, in one list:13

position of c
tl.to(a, { x, duration: 1 })
  .to(b, { x, duration: 0.6 }, "<")
  .to(c, { x, duration: 0.8 })

left out, it is the end of the timeline. c runs from 1 s to 1.8 s, and the timeline lasts 1.8 s.

three squares, a in cyan, b in amber and c in white, each on its own dashed lane. a runs for one second from the start and b for 0.6 s alongside it. a menu sets the position parameter of c, which lasts 0.8 s: left out, the start of b, the end of b, 0.3 s before or after the end, 0.2 s after b starts, half a second in, or half of c before the end. a track view under the lanes shows the three tweens as bars on a time axis with a playhead, a line says in words where c starts and ends and how long the timeline lasts, a play button runs the timeline, and a slider scrubs it.

the bars move before anything plays: a position is worked out when the tween is added.

the step-by-step movies elsewhere on this site, like the one on merge sort, are gsap timelines. site/src/visuals/kit/use-timeline.ts takes one from each figure, reads its chapters from labels named c0, c1 and on, and seeks with time() when you tap or drag the progress bar.

what trips people up:

easing

an ease maps time to value: progress through the duration goes in, 0 to 1, and how far along the value is comes out. the families are power1 to power4 (quad, cubic, quart, quint), sine, expo, circ, back, elastic and bounce, each with .in, .out and .inOut, plus steps(n) and none, which is linear. a bare name like power2 means .out.1516

the power outs are 1 − (1 − p)n+1: at half time, power1.out is 75% of the way, power2.out 87.5%, power4.out 97%. back runs past the end and settles; with the default overshoot of 1.70158 the peak is about 10% over. elastic takes an amplitude and a period, 1 and 0.3 by default. bounce reaches the end, then bounces three times, each bounce a quarter the height of the one before. steps(5) jumps five times.16

gsap.to('.box', { x: 200, ease: 'power2.out' }); // fast start, long settle
gsap.to('.box', { x: 200, ease: 'back.out(1.7)' }); // past the end, then back
gsap.to('.box', { x: 200, ease: 'elastic.out(1, 0.3)' }); // amplitude, period
gsap.to('.box', { x: 200, ease: 'steps(5)' }); // five jumps
gsap.to('.box', { x: 200, ease: 'none' }); // linear

gsap.defaults({ ease: 'power2.out', duration: 0.6 }); // for everything after this line
gsap.timeline({ defaults: { ease: 'power2.inOut' } }); // or for one timeline's children
ease
{
  duration: 1.2,
  ease: "power1.out",
}

halfway through the time, it is 75% of the way there.

a menu of fifteen eases, from none and the power family to back, elastic, bounce and steps. the chosen ease is drawn as a curve, time across and value up, over a dashed straight line for no ease, with a cyan line at 0 and an amber line at 1. on play a white dot crosses the plot at a steady pace while its height follows the ease, and a white square in a lane to the right rises with it. a line under the plot gives the value at half time, and how far past 1 or below 0 the ease goes.

a steep part of the curve is fast motion. above the line of 1, the square has gone past its end.

what trips people up:

stagger

when a tween has several targets, stagger spreads out their start times.17

with each: 0.1, five items in a row start at 0, 0.1, 0.2, 0.3 and 0.4 s. with amount: 1, the same five start at 0, 0.25, 0.5, 0.75 and 1 s. in a grid, the farthest cell starts at each times the grid’s longer side, wherever the wave starts: 0.5 s in a 5 by 5 grid with each: 0.1.18

gsap.from('.cell', { scale: 0, stagger: 0.1 }); // 0.1 s between starts
gsap.from('.cell', { scale: 0, stagger: { amount: 1, from: 'end' } }); // 1 s split among all, last first
gsap.from('.cell', { scale: 0, stagger: { each: 0.1, from: 'center', grid: [5, 5] } });
gsap.from('.cell', { scale: 0, stagger: (i) => i * i * 0.02 }); // any function of the index
from
stagger: {
  each: 0.1,
  from: "center",
  grid: [5, 5],
}

each cell shows its delay in seconds. cyan starts first, amber last, at 0.50 s.

a grid of 25 cells, each printing its delay in seconds for the chosen starting point: start, center, edges, end, index 6, or random. the first cell to move is outlined cyan and the last amber, at half a second. play shrinks and fades every cell, then grows them back in that order.

random shuffles the delays that start gives. gsap shuffles again for every tween; the figure seeds its own shuffle, so the page shows the same orders on every visit.

what trips people up:

scrolltrigger

ScrollTrigger ties a tween or a timeline to a scroll position. trigger is the element it watches.19

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

gsap.to('.card', {
  x: '100%',
  ease: 'none',
  scrollTrigger: {
    trigger: '.card',
    scroller: '.box', // leave it out for the page itself
    start: 'top 80%', // the card's top hits 80% down the box
    end: 'bottom 20%', // the card's bottom hits 20% down the box
    scrub: true, // or 1: a second to catch up
    markers: true, // while you work
  },
});

// toggled instead of scrubbed: play on the way in, reverse on the way back up
gsap.from('.card', {
  opacity: 0,
  y: 40,
  scrollTrigger: { trigger: '.card', start: 'top 80%', toggleActions: 'play none none reverse' },
});
mode
scroll this box ↓
and back up ↑
scrollTrigger: {
  trigger: card, scroller: box,
  start: "top 80%", end: "bottom 20%",
  scrub: true,
}

progress 0.00

a box 240 pixels tall with its own scrollbar. inside it, a white card labelled trigger, and two dashed lines across the box: cyan at 80% down, where the card's top starts the trigger, and amber at 20% down, where the card's bottom ends it. scrolling the box slides the card to the right while it is between the lines, a bar along the top fills with the trigger's progress, and a readout prints the progress and the scroll positions of the start and the end. a menu switches between scrub true, scrub 1, and toggleActions.

scroll the box, not the page. with scrub: 1, the card trails the scrollbar and catches up over a second.

what trips people up:

svg draw

DrawSVGPlugin reveals a stroke by animating stroke-dasharray and stroke-dashoffset. the drawSVG value is the part of the stroke that shows, start and end, in percent or px: "0% 100%" is all of it, "20% 80%" the middle three fifths. one value means from 0, so "100%" is the whole thing, and so is true. it works on path, line, polyline, polygon, rect, ellipse and circle, and it only touches the stroke.2223

import { DrawSVGPlugin } from 'gsap/DrawSVGPlugin';
gsap.registerPlugin(DrawSVGPlugin);

gsap.from('#path', { drawSVG: 0, duration: 1.5 }); // from nothing to the whole stroke
gsap.fromTo('#path', { drawSVG: '50% 50%' }, { drawSVG: '0% 100%' }); // from the middle outward
gsap.fromTo('#path', { drawSVG: '0 12%' }, { drawSVG: '88% 100%' }); // a dash that travels
draw it
gsap.fromTo(path,
  { drawSVG: 0 },
  { drawSVG: "100%" })

the grey line is the whole path. play strokes it in white.

one looping stroke drawn in grey across the panel. a menu picks how the white stroke over it is drawn: from the start, from the middle outward, from the end back, or as a short dash that travels its length. play runs the tween, the line of code shows the drawSVG values used, and a note gives the path's length and which part of it the end state shows.

the stroke's length is measured once, at the start of the tween. the value is a segment of it.

what trips people up:

svg morph

MorphSVGPlugin tweens one path’s d into another’s. it converts both to cubic béziers and adds points until they have the same number, then interpolates. it morphs path (and the points of a polyline or polygon); a circle, rect, ellipse or line becomes a path first with convertToPath.2425

shapeIndex picks which point of the start maps to the first point of the end. that matters for closed shapes: the wrong one crosses over itself halfway. type: "rotational" tweens the angles and lengths of the points instead of their x and y, which can look more natural.24

import { MorphSVGPlugin } from 'gsap/MorphSVGPlugin';
gsap.registerPlugin(MorphSVGPlugin);

MorphSVGPlugin.convertToPath('circle, rect, ellipse, line, polygon, polyline'); // paths first

gsap.to('#shape', { morphSVG: '#star', duration: 0.8 }); // a selector, an element, or a d string
gsap.to('#shape', { morphSVG: { shape: '#star', shapeIndex: 3 } }); // which point maps to the first
gsap.to('#shape', { morphSVG: { shape: '#star', type: 'rotational' } });
type
gsap.to(shape, {
  morphSVG: {
    shape: "#circle",
    type: "linear",
  },
})

pick a shape: the path morphs into it in 0.9 s. each point moves in a straight line to its new place.

one white shape and five buttons: circle, star, heart, bolt and square. a button morphs the shape into that one over nine tenths of a second, and a line under it says what moved and how. a menu switches the type between linear and rotational.

try circle to star with each type. linear moves each point straight; rotational swings it.

what trips people up:

flip

flip is a technique: first, last, invert, play. record where things are, change the layout any way you like, move them back to where they were with transforms, then animate the transforms away.26

the Flip plugin does the recording and the animating: Flip.getState(targets) before the change, Flip.from(state, vars) after it. it returns a timeline.27

import { Flip } from 'gsap/Flip';
gsap.registerPlugin(Flip);

const grid = document.querySelector('.grid');
const state = Flip.getState('.tile'); // first: where everything is now
grid.classList.toggle('as-row'); // last: change the layout
// invert and play: back to where they were, then animate to where they are
Flip.from(state, {
  duration: 0.5,
  ease: 'power2.inOut',
  absolute: true,
  onEnter: (els) => gsap.fromTo(els, { opacity: 0 }, { opacity: 1 }),
  onLeave: (els) => gsap.to(els, { opacity: 0 }),
});
const state = Flip.getState(tiles);
setOrder(next); // react renders
// then, in a layout effect:
Flip.from(state, {
  targets: tiles,
  absolute: true,
});

the tiles, in a row: a b c d e.

five tiles labelled a to e in a row, and three buttons: shuffle, reverse, and a switch between a row and a three-column grid. every change re-renders the tiles in their new places, flip slides each one from where it was, and a line spells out the new order.

react renders the new order. flip finds each tile again by its data-flip-id and slides it from its last place.

what trips people up:

split text

SplitText splits an element’s text into lines, words and characters, each in its own element (a div by default), so you can stagger them. revert() puts the original html back.2829

import { SplitText } from 'gsap/SplitText';
gsap.registerPlugin(SplitText);

const split = SplitText.create('.headline', { type: 'words, chars' });
gsap.from(split.chars, { y: 16, opacity: 0, stagger: 0.02 });
// later: split.revert() puts the original html back

SplitText.create('.headline', {
  type: 'lines',
  mask: 'lines', // a clipping wrapper per line
  autoSplit: true, // split again when the width or the fonts change
  // return the tween, so a re-split reverts it and picks it up where it was
  onSplit: (self) => gsap.from(self.lines, { yPercent: 100, stagger: 0.1 }),
});

every word moves on its own cue.

SplitText.create(el, {
  type: "chars,words",
}).chars
splits the line and staggers the pieces in, 0.03 s apart.

the sentence 'every word moves on its own cue.' and three buttons: chars, words, lines. a button splits the sentence that way, staggers the pieces in, and prints how many there were: 26 characters, 7 words, and however many lines fit the width.

spaces are not characters. the character split here includes words too, so no word breaks across lines.

what trips people up:

pitfalls

sources

  1. gsap.ticker (opens in a new tab) in the gsap docs: it updates the global timeline on every requestAnimationFrame. ↩

  2. the 3.13 release post (opens in a new tab) on gsap.com: thanks to webflow, the whole library, bonus plugins included, is free, commercial use included, and the plugins ship in the public npm package. the pricing page (opens in a new tab) says the entire library is free for all users, thanks to webflow. ↩

  3. the standard “no charge” license (opens in a new tab), effective april 30, 2025, read on 2026-10-28. the readme (opens in a new tab) and package.json at 3.15.0 point to it. it allows gsap on any website, web app or digital interface, rules out tools that build animations without code in competition with webflow’s, and leaves the intellectual property with webflow. its faq says commercial use is covered, plugins included. ↩

  4. gsap.to() (opens in a new tab) in the gsap docs: what a target can be, duration defaulting to 0.5, ease to "power1.out", and immediateRender to false for to() and true for from() and fromTo(). the defaults in the source are gsap-core.js (opens in a new tab), lines 17 to 21 and 1092. ↩ ↩2

  5. gsap.set() (opens in a new tab) in the gsap docs: a zero-duration to() tween. ↩

  6. gsap.defaults() (opens in a new tab) in the gsap docs. ↩

  7. the css plugin (opens in a new tab) page in the gsap docs: the transform shorthands, the fixed order they apply in, why a transform string costs more, xPercent, and autoAlpha. ↩ ↩2

  8. Tween (opens in a new tab) in the gsap docs: the methods. ↩

  9. gsap.from() (opens in a new tab) in the gsap docs: immediateRender is true for from() tweens, so the start state renders at once, whatever the delay, and immediateRender: false makes it wait, which is usually what you want in a timeline. ↩

  10. avoiding fouc (opens in a new tab) in the gsap docs: the browser paints before your javascript runs, so hide the elements with visibility: hidden in css and show them with autoAlpha. ↩

  11. common gsap mistakes (opens in a new tab) in the gsap docs: the from() logic issues, setting all transforms with gsap, adding tweens to a timeline that has finished, and css transitions on the same properties. ↩ ↩2 ↩3 ↩4

  12. Timeline (opens in a new tab) in the gsap docs: defaults, which a timeline’s tweens inherit when they are created, nesting with add(), timeScale(), progress(), and the controls. ↩ ↩2

  13. the position parameter (opens in a new tab) in the gsap docs, and how it is read in gsap-core.js (opens in a new tab), lines 390 to 412. ↩ ↩2

  14. a timeline’s to(), from(), fromTo() and set() end with return this in gsap-core.js (opens in a new tab), lines 1486 to 1507. ↩

  15. easing (opens in a new tab) in the gsap docs: the families, the default of power1.out, and which eases live in EasePack. ↩ ↩2

  16. the ease formulas in gsap-core.js (opens in a new tab), lines 1023 to 1092: how .out and .inOut derive from .in, the power family, back’s 1.70158, elastic’s 1 and 0.3 (0.45 for inOut), bounce’s four pieces, and steps. the halfway values, the 10% peak and the bounce heights are checked in site/src/visuals/gsap/ease.test.ts against gsap.parseEase. ↩ ↩2

  17. staggers (opens in a new tab) in the gsap docs: the number, object and function forms, and each, amount, from, grid, axis and ease. ↩ ↩2 ↩3

  18. distribute() in gsap-core.js (opens in a new tab), lines 452 to 506, which turns a stagger into each target’s delay, and the shuffle that "random" uses, line 450. the delays on this page are checked against it in site/src/visuals/gsap/stagger.test.ts. ↩ ↩2

  19. ScrollTrigger (opens in a new tab) in the gsap docs: start and end with their defaults, scrub, toggleActions (default "play none none none"), pin, once, scroller, markers, when positions are worked out and refresh(), and how duration works with a scrub. ↩ ↩2 ↩3

  20. ScrollTrigger.js (opens in a new tab): the start default, "0 100%" or "0 0" when pinned, at line 853, the end default at line 890, toggleActions: "play" at line 143, and the catch-up tween a numeric scrub makes at lines 654 to 661. ↩

  21. gsap with react (opens in a new tab) in the gsap docs: useGSAP reverts everything made inside it on unmount, and why cleanup matters with strict mode. ↩ ↩2

  22. DrawSVGPlugin (opens in a new tab) in the gsap docs: the value syntax, the elements it works on, that it needs a stroke, live, and splitting a path with several segments. ↩ ↩2 ↩3

  23. DrawSVGPlugin.js (opens in a new tab): how a value is read at lines 30 to 43 and 151 to 157, the lengths per element type at lines 44 to 104 with the warning about invisible elements at line 63, and what it writes to the stroke at lines 205 to 210. ↩ ↩2

  24. MorphSVGPlugin (opens in a new tab) in the gsap docs: converting to cubic béziers and adding points, convertToPath, shapeIndex, and type: "rotational". ↩ ↩2 ↩3 ↩4

  25. MorphSVGPlugin.js (opens in a new tab): only path, polyline and polygon targets at lines 650 to 657, shapeIndex defaulting to auto at line 664, data-original at line 675, and the type falling back to defaultType, which is "linear", at lines 695 and 853. ↩ ↩2

  26. paul lewis, flip your animations (opens in a new tab) (2015), where the technique and its name come from. ↩

  27. Flip (opens in a new tab) and Flip.from() (opens in a new tab) in the gsap docs: getState, from, absolute, scale, nested, onEnter, onLeave, absoluteOnLeave, data-flip-id, that it returns a timeline, and, for react, waiting for the render and passing targets. ↩ ↩2 ↩3

  28. SplitText (opens in a new tab) in the gsap docs: create, the default type, aria, mask, autoSplit with onSplit, revert, smartWrap, and the note that spaces are not characters. ↩ ↩2 ↩3 ↩4

  29. SplitText.ts (opens in a new tab): the div and aria: "auto" defaults at line 141, aria-hidden on each piece at line 149, the type default at line 355, aria-label at line 373, masks at lines 450 to 457, and revert() at lines 483 to 497. ↩

  30. gsap.context() (opens in a new tab) in the gsap docs. ↩

  31. gsap.matchMedia() (opens in a new tab) in the gsap docs, with the prefers-reduced-motion example. ↩

  32. accessible animation (opens in a new tab) in the gsap docs: the two matchMedia branches for reduced motion. ↩

  33. gsap.registerPlugin() (opens in a new tab) and the installation (opens in a new tab) page in the gsap docs: register once, so tree shaking keeps the plugin. ↩