Smooth Scroll CSS & JS Generator

Generate smooth scroll code for your website. Choose CSS scroll-behavior, vanilla JavaScript with custom easing, or Lenis library configuration — then copy the ready-to-use code.

Offset for fixed headers (e.g. 60-80px)
Negative = scroll past target
Lower = smoother (0.05-0.2)

Live Preview

Section 1 — Hero
Section 2 — Features
Section 3 — Pricing
Section 4 — Testimonials
Section 5 — Contact
Ad Space

How Does the Smooth Scroll Generator Work?

The Smooth Scroll Generator creates ready-to-use code snippets that add smooth scrolling behavior to any website. Instead of the browser jumping instantly to anchor links or page sections, smooth scrolling animates the transition so users can follow the page movement and maintain spatial context. This tool supports three methods: native CSS scroll-behavior, a custom vanilla JavaScript implementation with configurable easing functions, and the popular Lenis smooth scroll library used by award-winning websites.

Simply choose your preferred method, adjust the options to match your project needs, and click Generate Code. The tool produces clean, production-ready code that you can copy directly into your project. The live preview area demonstrates the scroll behavior in real time so you can see exactly how your configuration feels before deploying it.

CSS vs JavaScript vs Lenis Smooth Scroll

The CSS scroll-behavior: smooth property is the simplest approach. It requires zero JavaScript and is supported by all modern browsers. However, it offers no control over duration or easing — the browser decides the animation curve. This is ideal for simple sites that just need basic smooth anchor scrolling without adding script weight.

Vanilla JavaScript smooth scroll gives you full control over duration, easing function, and scroll offset. You can define custom cubic-bezier curves for precise animation timing. The generated code handles anchor link clicks automatically and optionally adds a scroll-to-top button. This is the best choice when you need fine-grained control without external dependencies.

Lenis is a lightweight smooth scroll library used by many Awwwards-winning websites. It provides buttery-smooth inertial scrolling with configurable lerp (linear interpolation), wheel and touch multipliers, and direction control. Lenis hooks into the browser's native scroll events and applies momentum-based smoothing, creating a premium feel. The generated code includes the CDN link, initialization, animation frame loop, and cleanup function.

Choosing the Right Easing Function

Easing functions control the acceleration curve of your scroll animation. Linear easing moves at constant speed — mechanical and rarely desirable for UI animations. Ease-in starts slow and accelerates, creating a sense of building momentum. Ease-out starts fast and decelerates, which feels natural for scrolling since the page appears to settle into position. Ease-in-out combines both, starting slow, speeding up in the middle, and slowing down at the end — this is the most commonly used easing for smooth scroll because it feels organic and polished.

For advanced control, use the cubic-bezier option to define custom timing curves. The four values (x1, y1, x2, y2) represent control points on a bezier curve. Values outside 0-1 on the y-axis create overshoot effects where the scroll briefly goes past the target before settling. Tools like cubic-bezier.com can help you visualize and fine-tune your custom curve.

Performance Tips for Smooth Scrolling

Smooth scrolling can cause jank if not implemented carefully. When using JavaScript-based solutions, avoid triggering layout recalculations during the scroll animation. Use requestAnimationFrame for timing instead of setInterval or setTimeout. For Lenis, keep the lerp value between 0.05 and 0.15 for the best balance of smoothness and responsiveness. Higher lerp values feel snappier but lose the premium smooth feel. Lower values create more lag between input and visual response, which can frustrate users on content-heavy pages.

Consider disabling smooth scroll for users who prefer reduced motion by checking prefers-reduced-motion media query. This is an accessibility best practice. All three methods generated by this tool can be wrapped in a reduced-motion check to respect user preferences.

Frequently Asked Questions

What is smooth scrolling?

Smooth scrolling is a technique that animates the page transition when navigating to anchor links or specific sections, instead of jumping instantly. It helps users maintain spatial context and creates a more polished user experience. Smooth scroll can be implemented with CSS, JavaScript, or libraries like Lenis.

Does CSS scroll-behavior smooth work in all browsers?

CSS scroll-behavior: smooth is supported in all modern browsers including Chrome, Firefox, Edge, and Safari 15.4+. For older Safari versions or IE11, you need a JavaScript fallback. This generator provides both CSS and JS options so you can choose the best approach for your browser support requirements.

What is Lenis and why use it for smooth scrolling?

Lenis is a lightweight open-source smooth scroll library that provides buttery-smooth inertial scrolling. Unlike CSS scroll-behavior, Lenis gives you control over interpolation (lerp), duration, wheel and touch multipliers, and direction. It is used by many award-winning websites and creates a premium scrolling feel.

How do I add a scroll-to-top button with smooth scroll?

This generator can include a scroll-to-top button in both the CSS and Vanilla JS methods. The button appears when the user scrolls down and smoothly scrolls back to the top when clicked. The generated code handles the visibility toggle, click event, and smooth animation automatically.

What easing function should I use for smooth scroll?

The most popular easing for smooth scroll is ease-in-out, which starts slow, speeds up, and slows down at the end. This feels natural and polished. For a more energetic feel, use ease-out (starts fast, slows at end). For custom curves, use the cubic-bezier option to define your own acceleration profile.

Is smooth scrolling bad for accessibility?

Smooth scrolling can cause discomfort for users with vestibular disorders. You should respect the prefers-reduced-motion media query to disable animations for users who request it. All code generated by this tool can be wrapped in a reduced-motion check to ensure accessibility compliance.