scrollIntoView() and history.replaceState() to enable smooth scrolling without changing the URL. #id format and add a data-smooth-scroll attribute to trigger the custom script.To create anchor links in Webflow that scroll to a section without altering the site address (i.e., without showing a “#section-id” in the URL), follow these steps.
about).#about, but we won’t link it this way in the next step.
#id to the browser’s URL. To prevent this, use custom JavaScript to override the behavior.
```javascript
<script>
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll('[data-smooth-scroll]').forEach(function (link) {
link.addEventListener("click", function (e) {
e.preventDefault();
const targetId = link.getAttribute("href").replace("#", "");
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({ behavior: "smooth" });
history.replaceState(null, null, ' ');
}
});
});
});
</script>
```
#about (or your section ID).data-smooth-scroll
This setup allows the link to scroll smoothly without updating the URL.
To create anchor links in Webflow that do not change the browser URL, assign an ID to the target section, use JavaScript with scrollIntoView() and custom attributes like data-smooth-scroll. This handles smooth scrolling while suppressing the URL fragment (#id).