All answers · Motion and code · 55 questions

GSAP, answered.

Correct, practical answers about GSAP, from the first tween to pinned ScrollTrigger scenes in React and Next.js. For developers and AI-assisted builders who want precise web animation that stays fast.

What is GSAP?

GSAP, the GreenSock Animation Platform, is a JavaScript animation library for animating anything a browser can change: CSS properties, SVG, canvas values, WebGL objects and plain JavaScript numbers. It is framework-agnostic, handles browser inconsistencies, and offers timelines for sequencing plus plugins such as ScrollTrigger for scroll animation, SplitText for text effects and Flip for layout transitions. It is one of the most widely used tools for scroll stories and staged hero animations.

GSAP templatesScroll animation guide

Is GSAP free for commercial use?

Yes. GSAP and all its plugins are free, including for commercial use. Since version 3.13, plugins that used to require a paid membership, such as SplitText, MorphSVG, DrawSVG and ScrollSmoother, ship in the public gsap package at no cost. GSAP is distributed under its own standard license rather than an open-source license like MIT, so read the license text on the GSAP site for the few restrictions it has before you ship.

GSAP templatesLicensing answers

How do I install GSAP?

Run npm install gsap, then import it with import { gsap } from "gsap". Plugins come from the same package, for example import { ScrollTrigger } from "gsap/ScrollTrigger", and must be registered once with gsap.registerPlugin(ScrollTrigger). Without a bundler, load gsap.min.js and the plugin files from a CDN such as jsDelivr with script tags, and the gsap global is ready to use. React projects can add the @gsap/react package for the useGSAP hook.

HTML and CSS templatesNext.js templates

What is the difference between gsap.to, gsap.from and gsap.fromTo?

gsap.to() animates from an element's current values to the values you give. gsap.from() animates from the values you give to the current values, which suits entrance animations. gsap.fromTo() takes both a start and an end object, so the result never depends on the element's current state. Each takes a target, such as a selector, element or array, and a vars object with properties plus settings like duration, delay, ease and stagger.

GSAP templatesAnimated website answers

What is gsap.set used for?

gsap.set() applies values instantly, with zero duration, using the same syntax as a tween. Use it to set starting states before an animation, apply transforms GSAP should track later, or position elements on load. Setting transforms through gsap.set rather than CSS lets GSAP record each transform component, such as x, y and rotation, so later tweens combine cleanly instead of overwriting the whole transform string.

GSAP templatesScroll animation answers

What is a GSAP timeline?

A GSAP timeline is a container that sequences tweens and other timelines on one playhead. You create one with gsap.timeline(), add tweens with .to(), .from() and .fromTo(), and they play one after another by default. The whole sequence can then be paused, reversed, sped up, scrubbed with scroll or nested in another timeline. A defaults object, such as { duration: 0.8, ease: "power2.out" }, applies shared settings to every child.

GSAP templatesPrompting for better motion

How does the position parameter work in a GSAP timeline?

The position parameter is the optional last argument that sets where a tween is placed in a timeline. A number is an absolute time in seconds. "+=0.5" adds a gap after the end of the timeline, and "-=0.5" overlaps by half a second. "<" aligns with the start of the previous tween, ">" with its end, and "<0.2" starts 0.2 seconds after the previous tween starts. Labels such as "intro+=1" work too.

GSAP templatesGSAP answers

What are labels in a GSAP timeline?

Labels are named points in a GSAP timeline that you add with tl.addLabel("reveal") or by passing a label name as a position. Tweens can be placed relative to them, such as "reveal+=0.3", and you can jump to them with tl.seek("reveal") or play from them with tl.play("reveal"). ScrollTrigger can snap to labels with snap: "labels", which makes scroll stories settle on meaningful steps.

GSAP templatesScroll animation templates

How do eases work in GSAP?

An ease controls the rate of change over a tween's duration. GSAP's default is "power1.out". Built-in families include power1 to power4, sine, expo, circ, back, elastic and bounce, each with .in, .out and .inOut variants, plus "none" for linear motion and steps() for stepped motion. Use .out for elements entering, .in for leaving, and "none" for scrubbed scroll tweens, because the scroll itself supplies the pacing.

GSAP templatesPrompting for better motion

What is stagger in GSAP?

stagger offsets the start time of each target in a tween so a group animates in sequence instead of all at once. stagger: 0.1 starts each element 0.1 seconds after the previous one. An object gives more control: each sets the gap per item, amount spreads a total time across all items, and from can start at "center", "end", "random" or an index. Grid staggers ripple outward across rows and columns.

GSAP templatesMotion components

What is autoAlpha in GSAP?

autoAlpha is a GSAP property that animates opacity and also sets visibility to hidden when opacity reaches 0, and back to inherit when it rises above 0. Hidden elements then cannot be clicked or focused while invisible. It is the usual choice for fades, and it pairs with a CSS rule that starts elements at visibility: hidden to stop them flashing before JavaScript runs.

GSAP templatesAccessibility

What is GSAP ScrollTrigger?

ScrollTrigger is the GSAP plugin that connects animations to scroll position. It can start an animation when an element reaches a point in the viewport, scrub a timeline so it follows the scrollbar, pin an element in place while a sequence plays, snap to positions and fire callbacks such as onEnter and onLeave. It is the engine behind most pinned scroll stories, and it is free like the rest of GSAP.

Scroll animation guideScroll animation templates

How do I register GSAP plugins?

Import the plugin from its own path in the gsap package and pass it to gsap.registerPlugin() once before use, for example gsap.registerPlugin(ScrollTrigger, SplitText). Registering keeps bundlers from tree-shaking the plugin away and links it to the core. Calling registerPlugin more than once is harmless. In React, also register the useGSAP hook. With script tags from a CDN, plugins load as globals and still need registering.

GSAP templatesNext.js templates

What do start and end mean in ScrollTrigger?

start and end define the scroll positions where a ScrollTrigger becomes active and inactive. Each is written as two words: the point on the trigger element, then the point in the viewport. "top center" starts when the trigger's top meets the viewport's center. The defaults are "top bottom" for start and "bottom top" for end. Values can use pixels or percentages, relative values like "+=500", or a function that returns a value.

Scroll animation guideScroll animation answers

What does scrub do in ScrollTrigger?

scrub links an animation's progress directly to the scroll position between start and end, so it moves forward and backward with the scrollbar instead of playing on its own. scrub: true locks it exactly to the scroll. A number, such as scrub: 1, adds smoothing so the animation takes about that many seconds to catch up, which feels softer. Use ease: "none" on scrubbed tweens for even pacing.

Scroll animation guideScroll film templates

How do I pin an element with ScrollTrigger?

Add pin: true to a ScrollTrigger to pin its trigger element, or pass a selector or element to pin something else. The element stays fixed from start to end while you scroll, and ScrollTrigger adds spacing so the content after it waits. A common setup is start: "top top", end: "+=2000", pin: true and scrub: 1 on a timeline. Create pinned triggers in the order they appear on the page.

Scroll animation templatesScroll animation answers

What is pinSpacing in ScrollTrigger?

pinSpacing controls whether ScrollTrigger adds space after a pinned element equal to the pin's scroll duration. With the default true, padding is added so following content only arrives after the pinned scene finishes. Setting pinSpacing: false removes that space, so the next section scrolls up over the pinned one, which is useful for stacked card or overlap effects. Changing it changes total page height.

Scroll animation templatesGSAP templates

What are ScrollTrigger markers?

Markers are visual debugging guides you turn on with markers: true in a ScrollTrigger. They draw labeled lines for the start and end on the trigger element and matching lines on the scroller, so you can see exactly when the trigger activates as you scroll. You can pass an object to change their colors or font size. Always remove markers before shipping.

Scroll animation answersScroll animation guide

When should I call ScrollTrigger.refresh()?

Call ScrollTrigger.refresh() after anything changes the page layout that ScrollTrigger cannot detect, such as content loaded by script, images without set dimensions finishing late, accordions opening or fonts that change heights. Refresh recalculates every trigger's start and end. ScrollTrigger already refreshes on window load, resize and when the tab becomes visible, so you do not need it for those. Calling it on every scroll is wasteful.

Scroll animation answersFast sites on phones

What does invalidateOnRefresh do in ScrollTrigger?

invalidateOnRefresh: true makes the animation attached to a ScrollTrigger flush its recorded start values and recalculate them whenever ScrollTrigger refreshes, such as on resize. Combine it with function-based values, like x: () => -(track.scrollWidth - window.innerWidth), so distances that depend on the viewport stay correct. Without it, a horizontal scroll track measured on a wide screen overshoots or stops short after a resize.

Scroll animation templatesGSAP templates

What does toggleActions do in ScrollTrigger?

toggleActions sets what a non-scrubbed animation does at four moments: onEnter, onLeave, onEnterBack and onLeaveBack, in that order. Each slot takes an action such as play, pause, resume, reverse, restart, reset, complete or none. The default is "play none none none", which plays once. "play none none reverse" plays on the way down and reverses when scrolling back above the start.

Scroll animation answersGSAP templates

How do I make a horizontal scroll section with GSAP?

Pin the section and tween its inner track along x. Create a tween with x: () => -(track.scrollWidth - window.innerWidth) and ease: "none", attached to a ScrollTrigger with trigger set to the section, pin: true, scrub: 1, end: () => "+=" + track.scrollWidth and invalidateOnRefresh: true. To animate items as they slide into view, give nested ScrollTriggers containerAnimation set to that horizontal tween.

Scroll animation templatesScroll animation answers

What is snap in ScrollTrigger?

snap makes the scroll settle on set progress values after the user stops scrolling. snap: 0.25 snaps to quarters, an array snaps to listed values, and snap: "labels" snaps to the timeline's labels. An object adds control with snapTo, duration, delay and ease. Snapping suits step-based scroll stories, but keep it gentle, since aggressive snapping can feel like the page is fighting the user.

Scroll animation templatesAccessibility

What does ScrollTrigger.batch() do?

ScrollTrigger.batch() creates a trigger for each matching element but groups the callbacks of elements that enter within the same short window, so they can animate together with a stagger. For example, ScrollTrigger.batch(".card", { onEnter: (batch) => gsap.to(batch, { autoAlpha: 1, y: 0, stagger: 0.1 }) }) reveals rows of cards as groups. It replaces creating dozens of separate tweens for a grid.

Motion componentsGSAP templates

What is GSAP SplitText?

SplitText is a GSAP plugin that splits an element's text into lines, words and characters, each wrapped in its own element, so you can animate them individually. A typical use is SplitText.create(".headline", { type: "lines, words", mask: "lines" }) and then gsap.from on the lines with a stagger, so text rises from behind a mask. Its autoSplit option re-splits when fonts load or the width changes. SplitText is free.

GSAP templatesAnimated website answers

Is GSAP SplitText accessible for screen readers?

Yes, by default in current versions. SplitText adds an aria-label with the original text to the split element and hides the generated line, word and character wrappers from assistive technology with aria-hidden, so screen readers read the sentence once instead of letter by letter. Keep the original text in the HTML, play split animations once, and skip them or use a simple fade when prefers-reduced-motion is set.

AccessibilityReduced motion guide

How do I use GSAP with React?

Install gsap and @gsap/react, register the hook with gsap.registerPlugin(useGSAP), and create animations inside useGSAP(() => { ... }, { scope: containerRef }). The scope lets selector text like ".box" match only inside your component, and every animation and ScrollTrigger made inside is reverted automatically when the component unmounts. Use refs for the elements you target and avoid putting animation values in React state.

Next.js templatesGSAP templates

What is the useGSAP hook?

useGSAP is a React hook from the @gsap/react package that replaces useEffect or useLayoutEffect for GSAP code. It wraps your animations in gsap.context() and reverts them on unmount, so tweens and ScrollTriggers never leak. It accepts a config with scope for scoped selectors, dependencies to re-run when values change, and revertOnUpdate to revert before each re-run. It runs as a layout effect on the client, which avoids a flash before animation starts.

Next.js templatesGSAP answers

How do I clean up GSAP animations in React?

Create animations inside useGSAP and cleanup happens automatically: on unmount it calls revert on the underlying gsap.context(), killing tweens, timelines and ScrollTriggers and restoring inline styles. If you use plain useEffect instead, create a context with const ctx = gsap.context(() => { ... }, ref) and return () => ctx.revert(). Animations created later in event handlers need contextSafe so they are cleaned up too.

Next.js templatesGSAP templates

What is contextSafe in useGSAP?

contextSafe is a function returned by useGSAP that wraps callbacks created after the hook runs, such as click or hover handlers, so animations they create are recorded in the same GSAP context and reverted on unmount. Use it as const { contextSafe } = useGSAP({ scope: ref }), then const onClick = contextSafe(() => gsap.to(".box", { rotation: 180 })). Without it, those later tweens are not cleaned up and scoped selectors do not apply.

Next.js templatesGSAP answers

What is gsap.context()?

gsap.context() collects every GSAP animation and ScrollTrigger created inside its function so you can revert or kill them all with one call to ctx.revert(). Passing a scope element as the second argument makes selector strings match only inside that element. It is the cleanup mechanism behind the useGSAP hook and works in any framework, such as Vue, Svelte or plain JavaScript components that mount and unmount.

GSAP templatesHTML and CSS templates

How do I use GSAP in Next.js?

Put GSAP code in a Client Component by adding "use client" at the top of the file, since GSAP needs the browser DOM. Register plugins in that file, create animations in useGSAP so they run only in the browser after the component mounts, and target elements with refs. Server Components can still render the markup around it. Keep the animated part small so most of the page stays server-rendered.

Next.js templatesUse with v0

Why does GSAP throw window is not defined during server rendering?

The error appears when GSAP code that touches window or document runs on the server, where those objects do not exist. In Next.js or other server-rendering frameworks, run animation code only inside useGSAP, useEffect or useLayoutEffect, which execute in the browser, and mark the component with "use client". Avoid calling DOM methods or creating ScrollTriggers at module top level in files that are imported on the server.

Next.js templatesGSAP answers

How do I keep ScrollTrigger working across Next.js route changes?

Create every ScrollTrigger inside useGSAP in the component that owns it, so leaving a page reverts its triggers and pins automatically. Stale triggers from a previous route cause wrong positions or leftover pin spacing. On the new page, layout can shift as images load, so give media fixed dimensions and call ScrollTrigger.refresh() once late content settles. If a smooth scroll library is used, reset scroll to the top on navigation.

Next.js templatesScroll animation answers

Should I use GSAP or CSS animations?

Use CSS for hover states, simple transitions, looping keyframes and, in supporting browsers, simple scroll-driven reveals, since it needs no library. Use GSAP when you need sequencing across many elements, runtime control such as pause, reverse or seek, pinned and scrubbed scroll scenes, animation of SVG, canvas or WebGL values, or consistent behavior across browsers. Both animate transform and opacity at similar cost. Do not let both animate the same property on one element.

Animated website answersScroll animation guide

GSAP vs Motion: which should I use for React?

Use Motion when you want declarative animation in React components: props like animate and whileInView, layout animations when elements move in the DOM, and exit animations through AnimatePresence. Use GSAP when you need long choreographed timelines, pinned and scrubbed scroll scenes with ScrollTrigger, text splitting or the same code outside React. Motion is MIT licensed, and GSAP is free under its own license. Some projects use Motion for UI and GSAP for scroll stories.

Motion componentsNext.js templates

Is GSAP good for animation performance?

Yes. GSAP is built for speed: it batches updates on a single requestAnimationFrame loop, caches transform values and avoids layout reads during tweens. Most real performance problems come from what is animated, not from GSAP. Animating width, top or filters on large elements forces layout or paint every frame in any library. Stick to transforms and opacity, limit how many elements move at once, and kill animations that are off screen.

Fast sites on phonesPerformance answers

Which properties should I animate with GSAP for smooth motion?

Animate GSAP's transform shortcuts and opacity: x, y, xPercent, yPercent, scale, rotation and autoAlpha. These map to CSS transforms and opacity, which browsers can composite without recalculating layout. Use xPercent and yPercent for movement relative to the element's own size. Avoid tweening left, top, width, height or margin on large or many elements, and use clip-path or filter sparingly, since they repaint.

Reduced motion and performanceFast sites on phones

What is gsap.matchMedia()?

gsap.matchMedia() runs animation code only while a media query matches and reverts it automatically when the query stops matching. You call mm.add("(min-width: 800px)", () => { ... }) for desktop-only animations, or pass an object of named conditions and read context.conditions inside one function. It handles breakpoint-specific ScrollTriggers and reduced-motion variants without manual cleanup, and mm.revert() removes everything.

Reduced motion guideFast sites on phones

How do I respect prefers-reduced-motion with GSAP?

Wrap motion in gsap.matchMedia() and create the full animations only under "(prefers-reduced-motion: no-preference)". Add a second condition for "(prefers-reduced-motion: reduce)" that shows the final state or a short fade instead. matchMedia reverts animations if the visitor changes the setting while the page is open. Make sure content is fully visible in the reduced branch, with no element left at opacity 0.

Reduced motion guidePerformance answers

What is gsap.quickTo?

gsap.quickTo() creates a reusable function that animates one property to a new value each time it is called, reusing a single tween instead of creating a new one. It is ideal for values that update constantly, such as a cursor follower: const xTo = gsap.quickTo(dot, "x", { duration: 0.4, ease: "power3" }), then call xTo(event.clientX) on each pointermove. The result is smooth trailing motion with little overhead.

Motion componentsUI Library

How do I pause, reverse or restart a GSAP animation?

Keep a reference to the tween or timeline, such as const tl = gsap.timeline(), and call its control methods: tl.play(), tl.pause(), tl.reverse(), tl.restart(), tl.seek(1.5), tl.progress(0.5) and tl.timeScale(2) to double speed. tl.kill() destroys it. Start an animation paused with paused: true in its vars, then play it on a click or when another event fires.

GSAP templatesAccessibility

What is the GSAP ticker?

The GSAP ticker is the single requestAnimationFrame loop that drives every GSAP animation. You can hook your own per-frame code into it with gsap.ticker.add(callback), which receives the time, and remove it with gsap.ticker.remove. Smooth scroll libraries such as Lenis are often driven from it so scrolling and animation share one loop. gsap.ticker.lagSmoothing() controls how GSAP handles long frame gaps.

Scroll animation answersGSAP templates

What is GSAP ScrollSmoother?

ScrollSmoother is a GSAP plugin built on ScrollTrigger that adds smooth scrolling while keeping native scroll underneath. It needs a wrapper element and a content element inside it, and you create it with ScrollSmoother.create({ smooth: 1, effects: true }). With effects on, data-speed and data-lag attributes add parallax and lag to individual elements. Keep position: fixed elements outside the wrapper. ScrollSmoother is free.

Scroll animation answersGSAP templates

What is the GSAP Flip plugin?

Flip is a GSAP plugin for animating layout changes using the FLIP technique: First, Last, Invert, Play. You record element positions with Flip.getState(targets), make the DOM or class change, such as moving an item to another grid, then call Flip.from(state, { duration: 0.6, ease: "power2.inOut" }). GSAP animates elements from old positions to new ones with transforms, so layout changes look smooth.

Motion componentsGSAP templates

What are the MorphSVG and DrawSVG plugins?

MorphSVG animates one SVG shape into another, even when the paths have different numbers of points, for logo transforms and icon morphs. DrawSVG animates an SVG stroke so lines appear to draw themselves, handling path length math for you, with values like drawSVG: "0%" to "100%". Both are free GSAP plugins, registered with gsap.registerPlugin(). SVG must be inline in the HTML for them to work.

Motion componentsGSAP templates

Can GSAP animate three.js objects?

Yes. GSAP can tween any numeric property of any JavaScript object, so gsap.to(mesh.rotation, { y: Math.PI * 2, duration: 2 }) or gsap.to(camera.position, { z: 5 }) animate three.js scenes directly, including shader uniforms such as material.uniforms.uProgress. Pair those tweens with ScrollTrigger and scrub to drive 3D scenes by scroll. Render the scene on each frame with three.js's own loop, or from gsap.ticker.

three.js templatesScroll 3D templatesthree.js answers

Can GSAP animate CSS variables?

Yes. GSAP tweens CSS custom properties by name, for example gsap.to("html", { "--hue": 220, duration: 1 }). Every rule that reads the variable updates, so one tween can recolor a theme, move a gradient or drive several elements at once. Numeric values with units work, and colors can be tweened too. Keep in mind that changing a variable read by layout properties still triggers layout.

GradientsTailwind templates

Does GSAP work with Tailwind CSS?

Yes. Tailwind handles layout and styling while GSAP animates elements by class, ref or selector. The one conflict to avoid is applying Tailwind transition utilities, such as transition-all or transition-transform, to an element GSAP animates, because the CSS transition then delays every GSAP update and the motion feels laggy. Let GSAP own the animated properties and Tailwind own the rest.

Tailwind templatesGSAP templates

Why do elements flash before my GSAP from() animation starts?

The flash happens because the browser paints the elements in their final state before JavaScript runs and gsap.from() sets the starting values. Fix it by hiding them in CSS first, for example visibility: hidden on the animated elements, then animating with autoAlpha: 1 using gsap.to or fromTo. Add the hiding rule only when a js class is present on the html element, so the content stays visible if scripts fail.

GSAP templatesScroll animation guide

Why does my GSAP animation break in React Strict Mode?

React 18 Strict Mode runs effects twice in development to expose missing cleanup. If a gsap.from() runs twice without cleanup, the second run starts from the already-applied from values, so elements can end up stuck invisible, and ScrollTriggers get duplicated. useGSAP fixes this by reverting the first run before the second. Production builds run effects once, but the cleanup is still needed for unmounts.

Next.js templatesGSAP answers

Can AI coding tools write GSAP animations?

Yes. Claude Code, Cursor, Codex, ChatGPT and similar tools write GSAP timelines and ScrollTrigger scenes well when the prompt is specific: name each element, its start and end states, durations, eases, scroll start and end points, pinning, and the reduced-motion fallback. Vague prompts get generic fades. AnimatedWebs templates are detailed build prompts, and its GSAP collection groups templates built around GSAP timelines and ScrollTrigger.

Prompting for better motionUse with Claude CodeGSAP templates

Where can I find GSAP animation website templates?

AnimatedWebs has a GSAP animation collection of websites animated with GSAP: ScrollTrigger timelines that choreograph the hero, pinned chapters, split text and staged page changes. Many have a live demo you can play before using them. Each template delivers a build prompt and design system rather than a code download, and your AI tool writes the GSAP code. The catalog holds 1,777 items in 20 collections.

GSAP templatesCollections

How do I add an AnimatedWebs GSAP template with Claude Code or Cursor?

Connect Claude Code or Cursor to the AnimatedWebs MCP server at https://mcp.animatedwebs.com, then ask the agent to find a GSAP template and build it in your project. The server has 15 tools, including catalog search and template fetch, and signs you in through the browser on first use, with free accounts working for free prompts. You can also copy the build prompt from the template page and paste it into the agent.

Claude Code setupCursor setupMCP answers

Should I use Lenis or GSAP ScrollSmoother for smooth scrolling?

Both smooth scrolling and both work with ScrollTrigger, so choose by setup. Lenis is a small standalone library that smooths the native window scroll without wrapper elements, which makes it easy to add to an existing layout. ScrollSmoother needs wrapper and content elements but adds built-in data-speed and data-lag parallax effects tied to ScrollTrigger. Use only one of them on a page, and disable smoothing under reduced motion.

Scroll animation answersReduced motion guide