Shopify themes, liquid, logos, and UX
Hey guys, how can I add that button to the bottom-right corner so that when I click it, it scrolls me all the way to the top?
I want this for both mobile and desktop.
Here’s the store where it is: https://tomnoske.store/
(Just scroll down so you can see it)
I would like to add the same thing to my store, and make sure it works on both desktop and mobile.
Here’s my store: https://1049xn-ya.myshopify.com/
Thanks a lot,
Tim
Solved! Go to the solution
This is an accepted solution.
Hi @CreatorTim
Hey there! Adding a "Scroll to Top" button is a great idea—it’s user-friendly and looks clean. Here’s how you can do it, step by step, so it works on both mobile and desktop. Don’t worry; it’s not as complicated as it seems!
You’ll need to include the HTML code for the button in your Shopify theme. Follow these steps:
html
Copy code
<div id="scrollToTop" style="display: none; position: fixed; bottom: 20px; right: 20px; z-index: 1000;">
<button style="background-color: #000; color: #fff; border: none; padding: 10px; border-radius: 5px; cursor: pointer;">
↑ Top
</button>
</div>
Now, you’ll make the button look good and ensure it’s positioned properly.
css
Copy code
#scrollToTop {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
#scrollToTop button {
background-color: #000;
color: #fff;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
Finally, let’s make the button work. Add this script to your theme.liquid file, just above the </body> tag:
javascript
Copy code
<script>
// Show the button when scrolling
window.onscroll = function() {
var button = document.getElementById("scrollToTop");
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
button.style.display = "block";
} else {
button.style.display = "none";
}
};
// Scroll to top when the button is clicked
document.getElementById("scrollToTop").addEventListener("click", function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
</script>
That’s it! You now have a "Scroll to Top" button that works on both desktop and mobile. If something doesn’t work or you need help with customization, let me know—I’m happy to assist.
Best regards,
Daisy.
This is an accepted solution.
Hi @CreatorTim
Hey there! Adding a "Scroll to Top" button is a great idea—it’s user-friendly and looks clean. Here’s how you can do it, step by step, so it works on both mobile and desktop. Don’t worry; it’s not as complicated as it seems!
You’ll need to include the HTML code for the button in your Shopify theme. Follow these steps:
html
Copy code
<div id="scrollToTop" style="display: none; position: fixed; bottom: 20px; right: 20px; z-index: 1000;">
<button style="background-color: #000; color: #fff; border: none; padding: 10px; border-radius: 5px; cursor: pointer;">
↑ Top
</button>
</div>
Now, you’ll make the button look good and ensure it’s positioned properly.
css
Copy code
#scrollToTop {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
#scrollToTop button {
background-color: #000;
color: #fff;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
Finally, let’s make the button work. Add this script to your theme.liquid file, just above the </body> tag:
javascript
Copy code
<script>
// Show the button when scrolling
window.onscroll = function() {
var button = document.getElementById("scrollToTop");
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
button.style.display = "block";
} else {
button.style.display = "none";
}
};
// Scroll to top when the button is clicked
document.getElementById("scrollToTop").addEventListener("click", function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
</script>
That’s it! You now have a "Scroll to Top" button that works on both desktop and mobile. If something doesn’t work or you need help with customization, let me know—I’m happy to assist.
Best regards,
Daisy.
But how can I adjust the design so that the arrow inside is smaller, it's in a gray circle, and it has more spacing? Like, move it further away from the bottom and the right.
Thank you so much!
Tim
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025