Add a Back to top button on long pages
If you have pages that are long and require a lot of scrolling, then you can add a Back to the top button to your theme.
Create a back-to-the-top snippet
Desktop
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, click the … button to open the actions menu, and then click Edit code.
- In the Snippets directory, click Add a new snippet.
- Name your snippet
back-to-the-top
, then click Create snippet. Your snippet file opens in the code editor.
- Paste the following code into your newly created
back-to-the-top
file:
- Click Save.
iPhone
- From the Shopify app, tap the … button.
- In the Sales channels section, tap Online Store.
- Tap Manage themes.
- Find the theme you want to edit, click the … button to open the actions menu, and then click Edit code.
- In the Snippets directory, click Add a new snippet.
- Name your snippet
back-to-the-top
, then click Create snippet. Your snippet file opens in the code editor.
- Paste the following code into your newly created
back-to-the-top
file:
- Click Save.
Android
- From the Shopify app, tap the … button.
- In the Sales channels section, tap Online Store.
- Tap Manage themes.
- Find the theme you want to edit, click the … button to open the actions menu, and then click Edit code.
- In the Snippets directory, click Add a new snippet.
- Name your snippet
back-to-the-top
, then click Create snippet. Your snippet file opens in the code editor.
- Paste the following code into your newly created
back-to-the-top
file:
- Click Save.
Include your snippet
- In the Layouts folder, open the
theme.liquid
file.
- Scroll to the bottom of the file. Right above the closing
</body>
tag, paste this code:
Your code should look like this:
- Click Save.
To customize your back to the top button, click here and look at the first lines of your snippet.
- To change the position of your button relative to the bottom of the browser, edit the
position_from_bottom
value:
- To change how far down a customer needs to scroll before the button is revealed, edit the
vertical_offset_for_trigger
value:
Demo store
Visit the demo store to see an example of this customization.