· 1 min read

How to Achieve Smooth Scroll with One Line of CSS

This article was auto-translated from Chinese. Some nuances may be lost in translation.

Just as I was happily implementing smooth scroll in Svelte, I discovered that it can actually be done with a single line of CSS:

html {
  scroll-behavior: smooth;
}

Aside from keeping browser support in mind, this completely saves developers the trouble of importing a library or implementing it themselves.

Screenshot_2020-05-07 scroll-behavior

It achieves smooth-scroll perfectly without needing to override the behavior of hashchange or state change. I’ll write another post some other day about how to achieve smooth scroll without CSS.

Related Posts

Explore Other Topics