Category · Navigation Menus Difficulty Level · Beginner Published on · August 22, 2025

Animated Back to Top Button

Smooth animated button that appears when scrolling down and smoothly scrolls back to the top of the page.

#scroll #button #animation #navigation #ux

Responsive Design

Yes

Dark Mode Support

Yes

lines

263

Browser Compatibility

Chrome · Firefox · Safari · Edge

Live Preview

Interact with the component without leaving the page.

200px

HTML

19

lines

CSS

161

lines

JavaScript

83

lines


                <div class="back-to-top-demo">
  <div class="demo-content">
    <h3>Scroll Down to See the Button</h3>
    <p>This is a demonstration of the back to top button. Scroll down to see it appear.</p>
    <div class="spacer"></div>
    <p>Keep scrolling...</p>
    <div class="spacer"></div>
    <p>Almost there...</p>
    <div class="spacer"></div>
    <p>Now scroll back up to see the button in action!</p>
  </div>
</div>

<button class="back-to-top" id="backToTopBtn" aria-label="Back to top" title="Back to top">
  <span class="sr-only">Back to top</span>
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
    <path d="M12 19V5M5 12l7-7 7 7"/>
  </svg>
</button>

              
19lines
710characters
HTMLLanguage

Browser Compatibility

Chrome

≥ 50

Firefox

≥ 45

Safari

≥ 10

Edge

≥ 15

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library →