npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lenis

v1.3.18

Published

How smooth scroll should be

Readme

LENIS

npm downloads size

Introduction

Lenis ("smooth" in latin) is a lightweight, robust, and performant smooth scroll library. It's designed by @darkroom.engineering to be simple to use and easy to integrate into your projects. It's built with performance in mind and is optimized for modern browsers. It's perfect for creating smooth scrolling experiences on your website such as WebGL scroll syncing, parallax effects, and much more, see Demo and Showcase.

Read our Manifesto to learn more about the inspiration behind Lenis.

Sponsors

If you’ve used Lenis and it made your site feel just a little more alive, consider sponsoring.

Your support helps us smooth out the internet one library at a time—and lets us keep building tools that care about the details most folks overlook.

Jesse Winton smsunarto bizarro itsoffbrand arkconclave Tamas Bodo glauber-sampaio cachet-studio OHO-Design joevingracien Lazar Filipovic

Packages

Installation

Using a package manager:

npm i lenis
# or
yarn add lenis
# or
pnpm add lenis
import Lenis from 'lenis'

Using scripts:

<script src="https://unpkg.com/[email protected]/dist/lenis.min.js"></script> 

Setup

Basic:

// Initialize Lenis
const lenis = new Lenis({
  autoRaf: true,
});

// Listen for the scroll event and log the event data
lenis.on('scroll', (e) => {
  console.log(e);
});

Custom raf loop:

// Initialize Lenis
const lenis = new Lenis();

// Use requestAnimationFrame to continuously update the scroll
function raf(time) {
  lenis.raf(time);
  requestAnimationFrame(raf);
}

requestAnimationFrame(raf);

Recommended CSS:

Import stylesheet:

import 'lenis/dist/lenis.css'

Or link the CSS file:

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/lenis.css">

Or add it manually:

See lenis.css stylesheet

GSAP ScrollTrigger:

// Initialize a new Lenis instance for smooth scrolling
const lenis = new Lenis();

// Synchronize Lenis scrolling with GSAP's ScrollTrigger plugin
lenis.on('scroll', ScrollTrigger.update);

// Add Lenis's requestAnimationFrame (raf) method to GSAP's ticker
// This ensures Lenis's smooth scroll animation updates on each GSAP tick
gsap.ticker.add((time) => {
  lenis.raf(time * 1000); // Convert time from seconds to milliseconds
});

// Disable lag smoothing in GSAP to prevent any delay in scroll animations
gsap.ticker.lagSmoothing(0);

React:

See documentation for lenis/react.

Settings

| Option | Type | Default | Description | |-------------------------|----------------------------|----------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | wrapper | HTMLElement, Window | window | The element that will be used as the scroll container. | | content | HTMLElement | document.documentElement | The element that contains the content that will be scrolled, usually wrapper's direct child. | | eventsTarget | HTMLElement, Window | wrapper | The element that will listen to wheel and touch events. | | smoothWheel | boolean | true | Smooth the scroll initiated by wheel events. | | lerp | number | 0.1 | Linear interpolation (lerp) intensity (between 0 and 1). | | duration | number | 1.2 | The duration of scroll animation (in seconds). Useless if lerp defined. | | easing | function | (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)) | The easing function to use for the scroll animation, our default is custom but you can pick one from Easings.net. Useless if lerp defined. | | orientation | string | vertical | The orientation of the scrolling. Can be vertical or horizontal. | | gestureOrientation | string | vertical | The orientation of the gestures. Can be vertical, horizontal or both. | | syncTouch | boolean | false | Mimic touch device scroll while allowing scroll sync (can be unstable on iOS<16). | | syncTouchLerp | number | 0.075 | Lerp applied during syncTouch inertia. | | touchInertiaExponent | number | 1.7 | Manage the strength of syncTouch inertia. | | wheelMultiplier | number | 1 | The multiplier to use for mouse wheel events. | | touchMultiplier | number | 1 | The multiplier to use for touch events. | | infinite | boolean | false | Enable infinite scrolling! syncTouch: true is required on touch devices (See example). | | autoResize | boolean | true | Resize instance automatically based on ResizeObserver. If false you must resize manually using .resize(). | | prevent | function | undefined | Manually prevent scroll to be smoothed based on elements traversed by events. If true is returned, it will prevent the scroll to be smoothed. Example: (node) => node.classList.contains('cookie-modal'). | | virtualScroll | function | undefined | Manually modify the events before they get consumed. If false is returned, the scroll will not be smoothed. Examples: (e) => { e.deltaY /= 2 } (to slow down vertical scroll) or ({ event }) => !event.shiftKey (to prevent scroll to be smoothed if shift key is pressed). | | overscroll | boolean | true | Similar to CSS overscroll-behavior (https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior). | | autoRaf | boolean | false | Whether or not to automatically run requestAnimationFrame loop. | | anchors | boolean, ScrollToOptions | false | Scroll to anchor links when clicked. If true is passed, it will enable anchor links with default options. If ScrollToOptions is passed, it will enable anchor links with the given options. | | autoToggle | boolean | false | Automatically start or stop the lenis instance based on the wrapper's overflow property, ⚠️ this requires Lenis recommended CSS. Safari > 17.3, Chrome > 116 and Firefox > 128 (https://caniuse.com/?search=transition-behavior). | | allowNestedScroll | boolean | false | Automatically allow nested scrollable elements to scroll natively. This is the simplest way to handle nested scroll. ⚠️ Can create performance issues since it checks the DOM tree on every scroll event. If that's a concern, use data-lenis-prevent attributes instead. | | naiveDimensions | boolean | false | If true, Lenis will use naive dimensions calculation. ⚠️ Be careful, this has a performance impact. | | stopInertiaOnNavigate | boolean | false | If true, Lenis will stop inertia when an internal link is clicked. |

Properties

| Property | Type | Description | |-------------------------|-------------------|----------------------------------------------------------------------------| | animatedScroll | number | Current scroll value | | dimensions | object | Dimensions instance | | direction | number | 1: scrolling up, -1: scrolling down | options | object | Instance options | | targetScroll | number | Target scroll value | | time | number | Time elapsed since instance creation | | actualScroll | number | Current scroll value registered by the browser | | lastVelocity | number | last scroll velocity | | velocity | number | Current scroll velocity | | isHorizontal (getter) | boolean | Whether or not the instance is horizontal | | isScrolling (getter) | boolean, string | Whether or not the scroll is being animated, smooth, native or false | | isStopped (getter) | boolean | Whether or not the user should be able to scroll | | limit (getter) | number | Maximum scroll value | | progress (getter) | number | Scroll progress from 0 to 1 | | rootElement (getter) | HTMLElement | Element on which Lenis is instanced | | scroll (getter) | number | Current scroll value (handles infinite scroll if activated) | | className (getter) | string | rootElement className |

Methods

| Method | Description | Arguments | |-----------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | raf(time) | Must be called every frame for internal usage. | time: in ms | | scrollTo(target, options) | Scroll to target. | target: goal to reachnumber: value to scroll in pixelsstring: CSS selector or keyword (top, left, start, bottom, right, end)HTMLElement: DOM elementoptionsoffset(number): equivalent to scroll-padding-toplerp(number): animation lerp intensityduration(number): animation duration (in seconds)easing(function): animation easingimmediate(boolean): ignore duration, easing and lerplock(boolean): whether or not to prevent the user from scrolling until the target is reachedforce(boolean): reach target even if instance is stoppedonComplete(function): called when the target is reacheduserData(object): this object will be forwarded through scroll events | | on(id, function) | id can be any of the following instance events to listen. | | | stop() | Pauses the scroll | | | start() | Resumes the scroll | | | resize() | Compute internal sizes, it has to be used if autoResize option is false. | | | destroy() | Destroys the instance and removes all events. | |

Events

| Event | Callback Arguments | |------------------|---------------------------| | scroll | Lenis instance | | virtual-scroll | {deltaX, deltaY, event} |

Considerations

Nested scroll

The simplest and most reliable way to handle nested scrollable elements is to use the allowNestedScroll option:

const lenis = new Lenis({
  allowNestedScroll: true,
})

This automatically detects nested scrollable elements and lets them scroll natively. However, this can create performance issues since Lenis needs to check the DOM tree on every scroll event. If you experience performance problems, use data-lenis-prevent instead.

Using HTML attributes

<div data-lenis-prevent>scrollable content</div>

See example

| Attribute | Description | |---------------------------------|--------------------------------------| | data-lenis-prevent | Prevent all smooth scroll events | | data-lenis-prevent-wheel | Prevent wheel events only | | data-lenis-prevent-touch | Prevent touch events only | | data-lenis-prevent-vertical | Prevent vertical scroll events only | | data-lenis-prevent-horizontal | Prevent horizontal scroll events only|

Using Javascript

<div id="modal">scrollable content</div>
const lenis = new Lenis({
  prevent: (node) => node.id === 'modal',
})

See example

Anchor links

By default, Lenis will prevent anchor links from working while scrolling. To enable them, you must set anchors: true.

new Lenis({
  anchors: true
})

You can also use scrollTo options:

new Lenis({
  anchors: {
    offset: 100,
    onComplete: ()=>{
      console.log('scrolled to anchor')
    }
  }
})

Limitations

  • no support for CSS scroll-snap, you must use (lenis/snap)
  • capped to 60fps on Safari (source) and 30fps on low power mode
  • smooth scroll will stop working over iframe since they don't forward wheel events
  • position fixed seems to lag on MacOS Safari pre-M1 (source)
  • touch events may behave unexpectedly when syncTouch is enabled on iOS < 16
  • nested scroll containers require proper configuration to work correctly

Troubleshooting

  • Make sure you use the latest version of Lenis
  • Include the recommended CSS
  • If using GSAP ScrollTrigger, ensure proper integration (see GSAP ScrollTrigger setup section)
  • Test without Lenis to ensure your element/page is scrollable
  • Be sure to use autoRaf: true or manually call lenis.raf(time) in your animation loop

Tutorials

Plugins

License

MIT © darkroom.engineering