{"id":6801,"date":"2025-02-05T01:00:00","date_gmt":"2025-02-05T01:00:00","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/?p=6801"},"modified":"2025-02-04T09:34:54","modified_gmt":"2025-02-04T09:34:54","slug":"how-to-add-back-to-top-button-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/how-to-add-back-to-top-button-in-magento-2\/","title":{"rendered":"How to Add Back to Top Button in Magento 2? &#8211; Easiest Way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Shoppers love simple navigation, and scroll to top button is one of them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Scroll to Top Button?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Scroll to top button is a simple navigation button that takes the shopper to the top of the page without any manual scrolling.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Like this:\u00a0<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1999\" height=\"1292\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend.png\" alt=\"Scroll to Top Preview on Frontend\" class=\"wp-image-6802\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend.png 1999w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-250x162.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-700x452.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-768x496.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-1536x993.png 1536w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-403x260.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-964x623.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-120x78.png 120w\" sizes=\"auto, (max-width: 1999px) 100vw, 1999px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Your shopper simply clicks the button and is navigated directly to the top. In this blog, I will show you the easiest way to add back to the top button in Magento 2 among the different options you have.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Options to Add Back to Top Button in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You have two options to add back to top button in Magento 2:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Using a Third-party Extension &#8211;<\/strong> Here, with the help of a third-party extension, you can implement this feature, but it is an expensive solution for adding a simple functionality to your store.\u00a0<\/li>\n\n\n\n<li><strong>Using a Widget in Admin &#8211; <\/strong>Display you a Magento 2 scroll to top button with a simple code that won&#8217;t even cost you a penny and easily shows the functionality.\u00a0<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Follow these steps to manually add scroll to the top Magento 2.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Add Back to Top Button in Magento 2 Using a Widget<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Add a New Block<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In your Magento 2 admin, go to <strong>Content &gt; Blocks <\/strong>and add a new block. Now, enter the following details for the block:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Enabled &#8211;<\/strong> Yes<\/li>\n\n\n\n<li><strong>Block Title &#8211; <\/strong>Meetanshi Back to Top<\/li>\n\n\n\n<li><strong>Identifier &#8211; <\/strong>back-to-top<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add the HTML Code&nbsp;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Select the applicable store view for the back-to-top functionality.&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1818\" height=\"1190\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code.png\" alt=\"Add the HTML Code\" class=\"wp-image-6804\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code.png 1818w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-250x164.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-700x458.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-768x503.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-1536x1005.png 1536w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-403x264.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-964x631.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/2-Add-the-HTML-Code-120x79.png 120w\" sizes=\"auto, (max-width: 1818px) 100vw, 1818px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">And insert the following HTML code in the block content:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Meetanshi Scroll to Top Button Starts-->\n&lt;div id=\"scroll-to-top\" style=\"display:none; position:fixed; bottom:20px; right:20px; z-index:1000;\">\n  &lt;a href=\"#top\" onclick=\"scrollToTop(event)\">\n    &lt;img alt=\"Meetanshi scroll-to-top button\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/01\/meetanshi-scroll-to-top-icon.png\" alt=\"Scroll to top\" style=\"width:50px; height:50px; display:block;\">\n  &lt;\/a>\n&lt;\/div>\n\n&lt;script>\n  document.addEventListener(\"DOMContentLoaded\", function () {\n    const scrollToTopButton = document.getElementById(\"scroll-to-top\");\n\n    window.addEventListener(\"scroll\", function () {\n      if (window.scrollY > 300) {\n        scrollToTopButton.style.display = \"block\";\n      } else {\n        scrollToTopButton.style.display = \"none\";\n      }\n    });\n\n    \/\/ Smooth scroll to top function\n    window.scrollToTop = function (event) {\n      event.preventDefault();\n      window.scrollTo({\n        top: 0,\n        behavior: \"smooth\"\n      });\n    };\n  });\n&lt;\/script>\n&lt;!-- Meetanshi Scroll to Top Button Ends-->\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, <strong>Save<\/strong> the block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, go to <strong>Content &gt; Widgets <\/strong>and add a new widget. Choose the widget type as <strong>CMS Static Block <\/strong>and select your store\u2019s active theme. Enter a title for the widget, i.e. Back to Top.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Choose the store view for the back to top button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"885\" height=\"576\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block.png\" alt=\"Now Add New Widgets as CMS Static Block\" class=\"wp-image-6806\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block.png 885w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block-250x163.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block-700x456.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block-768x500.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block-403x262.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/3-Now-Add-New-Widget-as-CMS-Static-Block-120x78.png 120w\" sizes=\"auto, (max-width: 885px) 100vw, 885px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Scroll down to <strong>Layout Updates<\/strong>, where you can set the pages where you want to display the scroll to top button (e.g., all pages) and choose <strong>Page Bottom<\/strong> for the container.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1016\" height=\"308\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates.png\" alt=\"Scroll Down to Layout Updates\" class=\"wp-image-6808\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates.png 1016w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates-250x76.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates-700x212.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates-768x233.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates-403x122.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates-964x292.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/4-Scroll-Down-to-Layout-Updates-120x36.png 120w\" sizes=\"auto, (max-width: 1016px) 100vw, 1016px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Click <strong>Save and Continue Edit<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Select the CMS Block&nbsp;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, choose the CMS block that we created in earlier steps for the back to top button and <strong>Save<\/strong> the widget.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"391\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget.png\" alt=\"Select the CMS Block Created Earlier and Save the Widget\" class=\"wp-image-6810\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget.png 1000w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget-250x98.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget-700x274.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget-768x300.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget-403x158.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget-964x377.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/5-Select-the-CMS-Block-Created-Earlier-and-Save-the-Widget-120x47.png 120w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">This will display a back to top button on pages whenever users scroll down the page.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1999\" height=\"1292\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend.png\" alt=\"Scroll to Top Preview on Frontend\" class=\"wp-image-6802\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend.png 1999w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-250x162.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-700x452.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-768x496.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-1536x993.png 1536w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-403x260.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-964x623.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/1-scroll-to-top-preview-on-frontend-120x78.png 120w\" sizes=\"auto, (max-width: 1999px) 100vw, 1999px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Isn&#8217;t it that simple? Try out this solution without spending on any pricey extension.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Shoppers love simple navigation, and scroll to top button is one of them. What is Scroll to Top Button? Scroll to top button is a&#8230;<\/p>\n","protected":false},"author":5,"featured_media":6815,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-6801","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/6801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=6801"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/6801\/revisions"}],"predecessor-version":[{"id":6817,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/6801\/revisions\/6817"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media\/6815"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=6801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=6801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=6801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}