Home CSS Create a smooth scroll effect with CSS only
CSS

Create a smooth scroll effect with CSS only

We used to reach for Javascript to achieve a smooth scrolling effect not so long ago. Even including a whole jQuery library for this effect only was nothing to frown upon. However, as the standards change, some sections of our work become easier. The smooth scrolling effect being one of them.

Usually used as a back-to-top action, it also serves well for linking anchor links, and makes the transition from one part of a page to another a little easier on the eyes.

Nowadays we can achieve this neat effect using native CSS only by adding a scroll behavior property to our html element in CSS:

html {
  scroll-behavior: smooth;
}

Other scroll behavior values are:

scroll-behavior: auto;
scroll-behavior: inherit;
scroll-behavior: initial;
scroll-behavior: revert;
scroll-behavior: revert-layer;
scroll-behavior: unset;

However, you will most likely ever only use the “smooth” or “auto” values.

Written by
Igor Bujas

I am a UI designer and front-end developer professional working mostly in the Shopify ecosystem. I've been working in the industry for so long that I was fixing bugs for IE5, and animating in Flash while it was still a Macromedia product. While not differentiating between the UI and the code, I am always looking to get outdoors for some alpine climbs or scuba dives. I also work as a Krav Maga instructor in Zagreb, Croatia.

Leave a comment

Related Articles

Tailwind CSS
CSSEnvironment Setup

A step-by-step tutorial on adding Tailwind CSS to your website

* Photo by Ross Parmly Tailwind CSS is a utility-first CSS framework...

CSSShopify for DevelopersShopify OS 2.0

New CSS for specific sections field in the Shopify 2.0 themes

Shopify launched a neat new feature for 2.0 themes to quickly add...

CSSShopify for Developers

Append a class to the Shopify menu item

Sometimes you need one menu item to be different than the rest...

CSSUX and UI

Simplified Development or a slew of Unnecessary Classes – Should you use Tailwind CSS?

Tailwind CSS is a utility-first CSS framework made for building custom user...

4 proven ways to speed up your Shopify store.

    We respect your privacy. Unsubscribe at anytime.