01.21 · Scroll-Based

Smooth (Inertia) Scroll

Scrolling glides to a stop instead of jumping. Best for portfolio sites.

Scroll it

Scroll or drag inside the box, or press Show me.

It catches your scroll

Instead of letting the browser jump, the box catches each turn of the wheel or swipe and turns it into a place to go.

Where to go, where it is

It keeps two positions: where you asked to go, and where the content is now. The gap between them is the glide.

A little closer each frame

Many times a second, the content moves part of the way toward where you asked to go, so it speeds off and then eases in.

It slides the content

The content moves as one piece instead of being scrolled, which keeps the movement smooth.

Momentum comes free

Flick and let go: the content keeps gliding after your hand stops, then settles.

Mind the trade-offs

Taking over scrolling can break keyboard scrolling, links to headings and find-in-page. Use it with care, and turn it off for visitors who ask for less motion.

Try it

Change a setting, then try it again or press Show me.

Glide

How long the content keeps moving after you stop.

Turn it on to compare with the browser's own scroll.

Copy the prompt

Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.

Add smooth scrolling to [the scrolling area or page you want to glide]. Catch the visitor's wheel, swipe and drag and turn each one into a target position, then on every frame move the content part of the remaining distance toward that target, so it glides and slows to a stop instead of jumping. Make that part exponential in the time since the last frame (one minus a fixed fraction to the power of that time), so the pace is the same on every screen. Move the content with a transform and keep a custom scrollbar in step with it. Keep keyboard scrolling, links to headings and find-in-page working. If the visitor has reduced motion turned on, use the browser's normal scrolling with no glide. Match the settings listed below.

Replace the words in brackets with your own element. Your settings are added at the end.

Free and open source. If this helped, a star on GitHub helps other people find it.

Star on GitHub

What it is

The full explanation is in README.md.

Good for

  • Portfolio sites
  • Brand pages
  • Scroll stories

Avoid on

  • Documentation
  • Forms
  • Dashboards