GSAP Motion

Lenis Smooth Scroll with GSAP: Setup, Ticker Sync and Trade-offs

Lenis smooth scroll setup with GSAP means driving one Lenis instance from the GSAP ticker instead of a separate requestAnimationFrame loop, so ScrollTrigger and the scroll position share a single clock. In my builds that means lenis.on("scroll", ScrollTrigger.update), gsap.ticker.add with time multiplied by 1000, lagSmoothing(0), and a reduced-motion check before Lenis is created at all.

By Saif Al Jahanwebdev-saif.com

What Lenis smooth scrolling actually changes

Lenis intercepts wheel and touch input and interpolates toward a target scroll position every frame, then writes that position with window.scrollTo. The result is consistent, eased scrolling across browsers, but the native scrolling path is replaced with main-thread work. ScrollTrigger should listen to the Lenis scroll event rather than the native one, so triggers and animations read the same interpolated number. With anchors enabled, in-page hash links route through lenis.scrollTo instead of jumping. The practical consequence is that Lenis and GSAP must share one clock: two independent loops writing the same scroll value produce jitter.

  • Interpolates a target value each frame via lerp or duration plus easing
  • Writes the result with window.scrollTo instead of native wheel smoothing
  • Emits a scroll event that ScrollTrigger can subscribe to
  • anchors: true routes hash links through lenis.scrollTo

The minimal Lenis instance and its config

Install the maintained package with npm i lenis — older tutorials reference @studio-freight/lenis. Import Lenis from "lenis" and the stylesheet from "lenis/dist/lenis.css", then create one instance after the DOM is ready. For easing, lerp: 0.1 is frame-rate independent; duration plus easing is the alternative, and mixing both meaningfully gives confusing results. smoothWheel defaults to true while syncTouch defaults to false, because native touch momentum is usually better than an emulation. wheelMultiplier and touchMultiplier tune speed. In recent versions autoRaf defaults to false, which is what you want when GSAP owns the loop. Keep the instance in a variable so you can stop or destroy it later.

  • npm i lenis; import Lenis and lenis/dist/lenis.css
  • lerp: 0.1 for frame-rate independent easing, or duration plus easing
  • smoothWheel: true with syncTouch: false by default
  • autoRaf: false when the GSAP ticker drives Lenis
  • data-lenis-prevent on nested scrollable panels

One clock: connect Lenis to gsap.ticker

The documented integration is three lines. First, lenis.on("scroll", ScrollTrigger.update) so every interpolated frame refreshes the triggers. Second, gsap.ticker.add((time) => lenis.raf(time * 1000)) — GSAP reports time in seconds and Lenis expects milliseconds, so the multiplication by 1000 is not optional. Third, gsap.ticker.lagSmoothing(0) stops GSAP from compressing a long frame after the tab was backgrounded, which would desynchronise the two timelines. Crucially, do not also run requestAnimationFrame(raf): that is a second loop writing the same scroll position. Choose one clock. On cleanup, remove the ticker callback with gsap.ticker.remove and call lenis.destroy().

  • lenis.on("scroll", ScrollTrigger.update)
  • gsap.ticker.add((time) => lenis.raf(time * 1000))
  • gsap.ticker.lagSmoothing(0) to prevent lag compression after tab switches
  • Never run a native rAF loop alongside the ticker callback
  • Remove the callback and call lenis.destroy() on unmount

The CSS Lenis needs or it fights your page

Lenis adds classes to the html element and expects matching rules. html.lenis, html.lenis body { height: auto } stops a fixed-height container from clipping the virtual scroll. .lenis.lenis-smooth { scroll-behavior: auto !important } overrides a global smooth-scroll declaration that would otherwise animate twice. .lenis-stopped { overflow: hidden } is what lenis.stop() relies on to lock the page behind a modal. .lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain } keeps nested scrollers from chaining back to the page. Import the packaged stylesheet rather than copying rules by hand, then verify that a theme reset is not overriding them. The shipped CSS also disables pointer events on iframes inside a smoothed page for the same reason.

  • html.lenis, html.lenis body { height: auto }
  • .lenis.lenis-smooth { scroll-behavior: auto !important }
  • .lenis-stopped { overflow: hidden } for modal locks
  • [data-lenis-prevent] { overscroll-behavior: contain } for nested scrollers
  • Import lenis/dist/lenis.css instead of duplicating rules

What smooth scrolling costs on the main thread

Lenis is nearly idle when the page is still and active while you scroll. Each frame it interpolates toward the target, calls window.scrollTo, fires a scroll event, and ScrollTrigger.update re-evaluates every registered trigger and attached animation. That is main-thread work layered on normal scrolling, competing with the input handling that INP measures. Cost scales with trigger count, pinning and animated element count, not with the Lenis bundle alone. On a mid-range Android phone, a page with dozens of pinned sections feels the difference. Profile an actual wheel or touch scroll in the DevTools Performance panel and read the long tasks beside the frame graph. Note the trade-off in lagSmoothing(0): smoother continuous scrolling, but a possible jump when the tab regains focus.

  • Per frame: interpolate, window.scrollTo, emit scroll, run ScrollTrigger.update
  • Cost grows with trigger and pin count, not just library size
  • Profile a real wheel or touch scroll in DevTools Performance
  • Watch long tasks and INP, not only LCP
  • lagSmoothing(0) can produce a jump after backgrounding the tab

When I turn Lenis off

The first switch is prefers-reduced-motion: reduce. I check it with window.matchMedia and skip instantiation entirely rather than creating an instance and calling stop(). I also leave native scrolling alone on touch-first layouts, where syncTouch adds work to emulate momentum the browser already handles well, and on pages with heavy pinning where update cost outweighs the polish. A site under a save-data signal, an interface whose primary interaction is an embedded scroll container, or a page with an INP budget already under pressure should keep native scroll. Lenis exposes stop(), start() and destroy() for runtime control; destroy() on route unmount so no listener or ticker callback survives. Motion should earn its cost.

  • matchMedia('(prefers-reduced-motion: reduce)') — skip creation, not just stop()
  • Touch-first pages keep native momentum with syncTouch: false
  • Heavy pinning, save-data, or an INP budget under pressure
  • stop() / start() for modal locks; destroy() on unmount
  • No smooth scroll in headless screenshot or visual-test jobs

How I ship it in WordPress and Next.js

In WordPress I enqueue Lenis only on templates that animate: wp_enqueue_style for lenis.css and wp_enqueue_script for a small motion.js that imports GSAP and ScrollTrigger, deferred with wp_script_add_data. The reduced-motion check lives in that script, not in functions.php, so the decision is made where the scroll actually runs. In Next.js I create the instance in useLayoutEffect, hold the ticker callback in a variable so I can pass it to gsap.ticker.remove, and call lenis.destroy() in cleanup — React StrictMode mounts effects twice in development, and two instances double the scroll. After dynamic content or a client-side route change, call ScrollTrigger.refresh(). I am Saif Al Jahan, a WordPress and PHP developer in Mymensingh, Bangladesh (GMT+6), and webdev-saif.com documents how I build motion that survives a Core Web Vitals audit.

  • wp_enqueue_style for Lenis CSS; deferred wp_enqueue_script for motion.js
  • Load GSAP and Lenis only on templates that use motion
  • Next.js: useLayoutEffect, gsap.ticker.remove, lenis.destroy() in cleanup
  • Make setup idempotent so StrictMode double-mounts cannot duplicate it
  • ScrollTrigger.refresh() after dynamic content or route changes

Frequently asked questions

Do I still need a requestAnimationFrame loop if I use the GSAP ticker?

No. Pick one clock. If gsap.ticker.add calls lenis.raf, do not also run requestAnimationFrame(raf). Both loops drive the same instance and write the same scroll position, which causes jitter and doubles the main-thread work. The GSAP route is preferred when ScrollTrigger is involved because triggers update on the same frame as the scroll interpolation. Keep a reference to the callback so you can remove it in cleanup.

Why multiply time by 1000 in the Lenis and GSAP integration?

GSAP ticker callbacks receive elapsed time in seconds, while Lenis raf expects a timestamp in milliseconds. Passing the raw value makes Lenis advance far too slowly, so the scroll never reaches its target. The documented recipe is gsap.ticker.add((time) => lenis.raf(time * 1000)). Pair it with lenis.on("scroll", ScrollTrigger.update) and gsap.ticker.lagSmoothing(0) so animations and scroll stay in step after a long frame.

Does Lenis smooth scrolling hurt Core Web Vitals?

It can affect INP rather than LCP, because the per-frame scroll work competes with input handling. Lenis itself is small, but every frame fires a scroll event and ScrollTrigger.update re-checks registered triggers; many pinned sections amplify that. I profile a real scroll in DevTools, check long tasks, and keep smooth scroll off for reduced-motion users and heavy pages. A page that fails the INP budget should drop Lenis before it drops its animations.

How do I disable Lenis for users who prefer reduced motion?

Check window.matchMedia("(prefers-reduced-motion: reduce)").matches before creating the instance and return early if it is true. Skipping construction is cleaner than instantiating and immediately calling stop(), because no listeners or ticker callbacks are registered in the first place. Also listen for changes to the media query if you want the page to respond live, and always call lenis.destroy() on unmount or route change.

Can Lenis handle nested scrollable containers?

Yes, but you must opt in. Add data-lenis-prevent to the inner scrollable element so Lenis ignores wheel events over it, and include the matching overscroll-behavior: contain rule from lenis.css. Without it, scrolling a sidebar or modal list can chain back to the page. Use lenis.stop() while a modal is open if you also need to lock the underlying document, then lenis.start() when it closes.

Should I use lerp or duration and easing in Lenis?

Choose one. lerp: 0.1 interpolates toward the target proportionally each frame and behaves consistently across refresh rates, which makes it my default. duration plus a custom easing function animates toward the target over a fixed time and is useful when you want a specific curve. Setting both sends conflicting instructions to the same interpolation step, so leave one at its default.

Written by Saif Al Jahan, webdev-saif.com · Mymensingh, Bangladesh. Last updated .