Create a Back to Top Button with Just HTML and CSS

Fixed-position “back to top” button using HTML anchor and CSS scroll-behavior: smooth for smooth scrolling

Most “back to top” buttons use JavaScript.

But they really don’t have to.

The browser already knows how to scroll. We just have to ask nicely.

All you need is:

  • Give your page an id="top" (usually on the <body>).
  • Add a link with href="#top" that scrolls back to the top.
  • Use position: fixed to pin it in the corner.
  • And scroll-behavior: smooth on the html for smooth transitions

No listeners. No scroll events. No extra code.

This is simpler, faster, and works everywhere. Sometimes, native HTML and CSS are all you need.

Checkout the codepen: https://codepen.io/theosoti/pen/KwdzKGx

To learn more tips about CSS, make sure to join my newsletter below ❤️

Related Articles

Explore more articles on front-end development, covering HTML, CSS and JavaScript for building high-performance websites.

    No strings attached, unsubscribe anytime!