How to add the back to top button only on homepage for Dawn theme?

Topic summary

A user seeks to add a “back to top” button exclusively on the homepage of their Dawn theme Shopify store.

Initial Solution:

  • Add a Custom Liquid section in the theme customizer
  • Use conditional logic ({% if template == 'index' %}) to display the button only on the homepage
  • Include basic HTML/CSS for the button functionality

Follow-up Issue:

  • The button’s position overlaps with an existing chat box widget
  • User requests adjustment to move the button higher on the page

Alternative Solution Provided:

  • Edit the theme.liquid file directly instead of using Custom Liquid
  • Insert complete code within the <body> tag, including:
    • CSS styling with customizable bottom and right positioning properties (currently set to 20px each)
    • JavaScript for scroll detection (appears after 300px scroll) and smooth scroll-to-top behavior
    • SVG icon for the button
  • Adjust the bottom value in CSS to resolve overlap issues

Status: Solutions provided; awaiting user confirmation on whether positioning adjustment resolves the overlap problem.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

How to add the back to top button only on homepage for Dawn theme?

Hi @NatalieY123 ,

Go to Customize, add a Custom Liquid section, and paste the code below.

{% if template == 'index' %}
    

    
{% endif %}

1 Like

thank for so much, but the position of the back to top button overlap with my chat box, can the back to top button move up a bit?

Good day, @NatalieY123 ,

To achieve this, simply follow these steps:

  1. Open your theme editor in Shopify, then click on Edit code.

  2. Find and open the theme.liquid file.

  3. Inside the theme.liquid file, place the following code (along with the styles) within the tag.
    Here is the code…

    #backToTop { display: none; /* Initially hidden */ width: 35px; height: 35px; position: fixed; right: 20px; /* You can adjust the position */ bottom: 20px; /* You can adjust the position */ background: powderblue; border: none; border-radius: 5px; text-align: center; line-height: 35px; cursor: pointer; z-index: 9999; } #backToTop .icon.icon-caret { transform: rotate(180deg); padding: 5px; vertical-align: middle; width: 25px; height: 25px; color: white; } #backToTop:hover { background-color: lightblue; } .show-back-to-top-btn { display: block; }

    {% if template == ‘index’ %}


    {% endif %}

If this was helpful and you have any further questions, please don’t hesitate to ask. If you found my solution useful, feel free to accept and like it. (S.P)

1 Like

Found my response useful? Like it and mark as Accepted Solution!