🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Add Back to Top Button in Shopify? – Easiest Way

By Sanjay JethvaUpdated on May 21, 2025 3 min read

Adding the scroll to top feature in Shopify makes the navigation super easy for shoppers, allowing them to head right back up without too many manual scrolls. 

Here, I will show you a direct way to add back to top button in Shopify. 

Methods to Add Back to Top in Shopify

You can add the Shopify scroll to top button in two ways:

  • Use an app where you can use a third-party tool to add the button on respective pages.
  • Add a simple code to your Shopify theme file directly, which can be easily customized as needed.

Using an app does come with monthly fees, which you can avoid simply by adding a code to your theme file.

Follow the below steps carefully to add scroll to top button without any additional cost

Manual Method to Add Back to Top Button Shopify

Step 1: Head to Your Shopify Theme File 

From your Shopify admin panel, head to Online Store > Themes.

Head to Your Shopify Theme File

Click on the three dots next to Customize and click Edit code.

Click Customize and Click Edit Code

Step 2: Add the Code 

Then, open the theme.liquid file and add the following code before the closing </body> tag:

<!-- Meetanshi Scroll to Top Button Starts-->
<div id="scroll-to-top" style="display:none; position:fixed; bottom:20px; right:20px; z-index:1000;">
  <a href="#top" onclick="scrollToTop(event)">
    <img alt="Meetanshi scroll-to-top button" src="https://blog.meetanshi.com/wp-content/uploads/2025/01/meetanshi-scroll-to-top-icon.png" alt="Scroll to top" style="width:50px; height:50px; display:block;">
  </a>
</div>

<script>
  document.addEventListener("DOMContentLoaded", function () {
    const scrollToTopButton = document.getElementById("scroll-to-top");

    window.addEventListener("scroll", function () {
      if (window.scrollY > 300) {
        scrollToTopButton.style.display = "block";
      } else {
        scrollToTopButton.style.display = "none";
      }
    });

    // Smooth scroll to top function
    window.scrollToTop = function (event) {
      event.preventDefault();
      window.scrollTo({
        top: 0,
        behavior: "smooth"
      });
    };
  });
</script>
<!-- Meetanshi Scroll to Top Button Ends-->

Like this:

Add the Code

Step 3: Hit Save and Preview

Finish this up by clicking Save.

Congratulations. You’ve successfully added a scroll to top button in Shopify. 🎉 Take a preview of your online store; it will appear as soon as you scroll down the page.

Thus, the customers can quickly go to the top without scrolling manually

Hit Save and Preview

That’s how easy it is to add the back to top button in Shopify using a simple code. Now, try it yourself. 

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.