Chapter 09 of 11Part 3 · GSAP

Scroll animation with GSAP and CSS

Tie motion to scroll with ScrollTrigger and CSS scroll-driven animations, and know when smooth scrolling is worth it.

11 minBy Zuzo StudioUpdated

11 min

In this chapter you will

  • tell a triggered scroll animation from a scrubbed one and pick the right kind
  • set up ScrollTrigger with trigger, start, end, scrub and a careful pin
  • write a CSS scroll-driven animation that degrades safely where it is not supported

Before you startThis builds on The GSAP timeline: sequencing a hero intro.

Check your understanding

3 questions

Q1You want a row of cards to rise into place when they reach the screen and stay put afterwards. Which setup fits best?

Show the answer

A ScrollTrigger with start: "top 80%" and once: true The animation starts when the section is well into view, plays at its own duration, and the trigger is removed afterwards so it never replays.

Q2A rule sets animation-timeline: view(); and then, on the next line, animation: rise linear both;. Nothing happens on scroll. Why?

Show the answer

The animation shorthand reset animation-timeline to auto The shorthand resets animation-timeline even though you cannot set it there, so animation-timeline must come after the shorthand.

Q3Cards use a CSS view() reveal wrapped in @supports (animation-timeline: view()). What does a reader on released Firefox see?

Show the answer

The cards in their normal, finished position with no animation Firefox skips the whole @supports block, so none of the animation rules apply and the cards show as the base CSS describes them.

Key takeaways

  1. A triggered animation plays on its own clock when an element arrives; a scrubbed one follows the scroll position, forwards and backwards.
  2. In ScrollTrigger, start and end each name a place on the trigger and a place on the viewport, such as "top 80%".
  3. Pinning takes over the reader's scroll, so keep pinned distances short and never animate the pinned element itself.
  4. CSS animation-timeline with view() or scroll() needs no JavaScript, but Firefox has not shipped it, so wrap it in @supports and keep the finished state as the default.
  5. Smooth scrolling libraries such as Lenis help keep WebGL in sync with scroll; most sites are better with native scrolling.
Up next · Chapter 10 · 9 min SVG line animation: make a path draw itself Make an SVG path draw itself with stroke-dasharray and stroke-dashoffset, in CSS or GSAP, without confusing screen readers.

02FAQ

Questions on this chapter

Something else on your mind? Email the studio and a designer, not a salesperson, replies within a day.

Can you make scroll animations with only CSS?

Yes, with CSS scroll-driven animations: set animation-timeline to scroll() or view() on a keyframe animation. They work in Chrome, Edge and Safari 26 and later, but not yet in released Firefox, so treat them as an enhancement.

What does scrub do in GSAP ScrollTrigger?

Scrub ties an animation's progress to the scroll position instead of time, so it moves forwards and backwards with the scrollbar. scrub: true follows exactly, and a number such as 0.5 is the seconds the animation takes to catch up.