Join the Webstudio community

Updated 7 months ago

Smooth scroll to section on the same page

At a glance

The community members are discussing how to create a smooth scroll to a section on the same page when a link is set to one of the buttons in the hero. The initial response suggests it's "super easy", and the community members provide various solutions, including adding html { scroll-behavior: smooth; } or applying it to the body tag. However, some community members express confusion on where to add the HTML. After some back-and-forth, the final solution is to add an ID to the target element at the top of the page, then create a link at the bottom of the page that links to the target ID, and add the <style>html { scroll-behavior: smooth; }</style> to the HTML. This solution is confirmed to work perfectly.

Hi, is there a way to make a smooth scroll to the section on the same page when a link is set to one of the buttons in the hero, for example?
J
J
O
11 comments
yep, it's super easy.
html {
scroll-behavior: smooth;
}
Make sure they are anchor links, not full paths that you're linking to.
sorry for my ignorance. Where do I add html?
you can create a property on the body tag, that should also work.
or better yet, a "smooth-scroll" token and apply it to the body.
sorry, not working for me. Maybe someone can create a short video and share it for all users..
Sorry, I was wrong. It needs to be on the html.

Here's the steps to create:
  1. Add ID onto element at top of page (eg: top-link)
  2. Add html embed with <style>html {scroll-behavior: smooth; }</style>
  3. Create link at bottom of page (place with fixed or absolute position) link it to the "top-link" target on the page
  4. You might need to publish to see this work
YEP, now its working perfectly. Thank you very very much.
We should really get this adjustable from the UI.
Add a reply
Sign up and join the conversation on Discord