---
title: "Discussion on \"Pure Vanilla JavaScript Smooth Scroll to Element on <a> anchor tag click #id\" | Hashnode"
description: "Discussion on \"Pure Vanilla JavaScript Smooth Scroll to Element on <a> anchor tag click #id\". It took me half an hour and countless of stackoverflow pages to find a perfect solution for a smooth scroll for <a> anchor links. \nSo I'm adding here it as a snippet for future googlers. \ndocument\n    .querySelectorAll('.nav__item a[href^=\"#\"]')\n    ..."
url: "https://hashnode.com/posts/pure-vanilla-javascript-smooth-scroll-to-element-on-lessagreater-anchor-tag-click-id/5f9aaeaaa1658252d1a7b61e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Pure Vanilla JavaScript Smooth Scroll to Element on <a> anchor tag click #id](https://blog.surjithctly.in/pure-vanilla-javascript-smooth-scroll-to-element-on-lessagreater-anchor-tag-click-id?utm_source=hashnode&utm_medium=feed)

It took me half an hour and countless of stackoverflow pages to find a perfect solution for a smooth scroll for <a> anchor links. So I'm adding here it as a snippet for future googlers. document .querySelectorAll('.nav\_\_item a\[href^="#"\]') ...

Oct 29, 2020 · 2 min read · blog.surjithctly.in  
Updated Nov 3, 2020  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#vanilla-js-1](https://hashnode.com/tag/vanilla-js-1)
-   [#js](https://hashnode.com/tag/js)

## Written by

[Surjith S M](https://hashnode.com/@surjithctly)

@surjithctly · Kerala, India

  
[View profile](https://hashnode.com/@surjithctly)

Freelance Web & UX Designer

Freelance Web &amp; UX Designer from Incredible India. I design and develop creative websites, landing pages and applications for startups and e

## Responses 2

Markdown supported · ⌘↵ to post

[Mohith Gupta Korangi](https://hashnode.com/@YouKnowWho)

[Oct 30, 2020](https://hashnode.com/posts/pure-vanilla-javascript-smooth-scroll-to-element-on-lessagreater-anchor-tag-click-id/5f9aaeaaa1658252d1a7b61e/comment/5f9bb5e5ff730d5cb8dedadf)

But we have a CSS property for smooth-scroll, right?? Why not use it??

[Surjith S M](https://hashnode.com/@surjithctly)

[Oct 30, 2020](https://hashnode.com/posts/pure-vanilla-javascript-smooth-scroll-to-element-on-lessagreater-anchor-tag-click-id/5f9aaeaaa1658252d1a7b61e/comment/5f9bb5e5ff730d5cb8dedadf#reply-5f9bcd8e1502575c97127467)

Trust me I tried that as well.. But in some cases you will feel its not flexible. So this will come in handy.

[Emily Boston](https://hashnode.com/@emilyboston)

[Oct 30, 2020](https://hashnode.com/posts/pure-vanilla-javascript-smooth-scroll-to-element-on-lessagreater-anchor-tag-click-id/5f9aaeaaa1658252d1a7b61e/comment/5f9b997d9dacc2579c58d5d2)

Bookmarked, thanks for sharing.
