Animated Back to Top Button
Smooth animated button that appears when scrolling down and smoothly scrolls back to the top of the page.
Responsive Design
Yes
Dark Mode Support
Yes
lines
241
Browser Compatibility
Chrome · Firefox · Safari · Edge
Live Preview
Interact with the component without leaving the page.
Overview
Smooth animated button that appears when scrolling down and smoothly scrolls back to the top of the page.
How to use
- Copy the HTML markup into your page.
- Paste the CSS into your stylesheet and ensure the selectors match your markup.
- Paste the JavaScript and load it after the markup.
- Adjust spacing, colors, and text to match your design system.
Customization tips
- Rename class names to avoid collisions with your existing CSS.
- Replace hard-coded colors with CSS variables for theming.
- Verify the layout at 320px, 768px, and 1024px widths.
- Test dark mode with your preferred background and text colors.
HTML
19
lines
CSS
149
lines
JavaScript
73
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>
Browser Compatibility
Chrome
>= 50
Firefox
>= 45
Safari
>= 10
Edge
>= 15