CSS Smooth Scroll

Improving the user experience of web applications has always been a priority of mine. I always come back to the same though I’ve had for 20 years: “users expect a web app to work — let’s make the app a joy to use.” Over the years we’ve employed JavaScript to improve the UX, but over […]

The post CSS Smooth Scroll appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

Improving the user experience of web applications has always been a priority of mine. I always come back to the same though I’ve had for 20 years: “users expect a web app to work — let’s make the app a joy to use.” Over the years we’ve employed JavaScript to improve the UX, but over time those strategies either become clunky or get baked into the web languages themselves. One such feature is smooth scrolling; a great UX improvement but annoying if imperfect. Did you know that you can implement smooth scrolling with just CSS?

The scroll-behavior CSS property controls the scrolling strategy for overflow elements with scrolling behavior, and only when triggered by navigation or CSSOM properties. The default scroll-behavior value is auto, which represents no visual effect — immediately scrolling to the target element with no animation. To provide users a smooth scrolling experience, you can use the smooth value:

/* slide between items */
.slideshow ul {
  scroll-behavior: smooth;
}

Of course you do lose some visual control when you use a native browser API — most notably animation speed and animation curve. On the positive side you don’t need to add kilobytes of JavaScript that you need to maintain to achieve a very similar effect!

The post CSS Smooth Scroll appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2021-04-19T11:09:43+00:00) CSS Smooth Scroll. Retrieved from https://www.scien.cx/2021/04/19/css-smooth-scroll/

MLA
" » CSS Smooth Scroll." David Walsh | Sciencx - Monday April 19, 2021, https://www.scien.cx/2021/04/19/css-smooth-scroll/
HARVARD
David Walsh | Sciencx Monday April 19, 2021 » CSS Smooth Scroll., viewed ,<https://www.scien.cx/2021/04/19/css-smooth-scroll/>
VANCOUVER
David Walsh | Sciencx - » CSS Smooth Scroll. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/19/css-smooth-scroll/
CHICAGO
" » CSS Smooth Scroll." David Walsh | Sciencx - Accessed . https://www.scien.cx/2021/04/19/css-smooth-scroll/
IEEE
" » CSS Smooth Scroll." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2021/04/19/css-smooth-scroll/. [Accessed: ]
rf:citation
» CSS Smooth Scroll | David Walsh | Sciencx | https://www.scien.cx/2021/04/19/css-smooth-scroll/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.