Skip to content

Scroll

The Scroll utility provides a small initializer to enable smooth scrolling for elements with a data-scroll attribute.

You can preview the scroll functionality in the Playground.

OptionTypeDescription
targetstringCSS selector for the scroll target (e.g. #section). If absent, the element’s href is used.
offsetnumberPixels to offset from the top after scroll (e.g. 80).
speednumberDuration of the animated scroll in milliseconds. If 0 or omitted, native smooth scrolling is used.
<!-- Basic link with default smooth scroll -->
<a href="#my-section" data-scroll>
Go to section
</a>
<!-- With options -->
<a
href="#my-section"
data-scroll="target:#my-section;offset:80;speed:500;">
Go to section
</a>