Is it possible to configure the previous and next buttons on a CMS collection's pagination to scroll back to the top of the section in Webflow?

Published on
September 22, 2023

Yes, it is possible to configure the previous and next buttons on a CMS collection's pagination to scroll back to the top of the section in Webflow. By default, when a user clicks on the previous or next button, the CMS collection will load the next set of items without scrolling back to the top. However, with some custom code, you can make this behavior change.

To achieve this, follow these steps:

  1. Open the Designer view in Webflow and navigate to the page where you have implemented the CMS collection.
  2. Select the pagination element or the collection list wrapper element on your page.
  3. Add a new custom attribute by clicking on the "Add Field" button in the Settings panel on the right-hand side.
  4. Name the attribute "data-wf-page-scroll" (without quotes) and set its value to "top".
  5. Now, go to the page's Settings panel and click on the "Custom Code" tab.
  6. In the <head> section of the HTML Embed Code, insert the following code:
<script>document.addEventListener('DOMContentLoaded', function() {  const paginationLinks = document.querySelectorAll('[data-wf-page-scroll="top"]');    paginationLinks.forEach(link => {    link.addEventListener('click', scrollToTop);  });    function scrollToTop() {    window.scrollTo({ top: 0, behavior: 'smooth' });  }});</script>
  1. Save and publish your site.

Now, when a user clicks on the previous or next button, the page will scroll back to the top of the section smoothly. This custom code binds the scroll to top behavior to the pagination links that have the custom attribute data-wf-page-scroll="top".

Please note that this solution requires custom code and accessing the "Custom Code" tab, which is only available for Webflow paid plans.

Additional Questions:

  1. How can I configure the pagination buttons to scroll to the top of the section in Webflow CMS collections?
  2. Can I customize the pagination behavior in Webflow CMS collections to scroll back to the top?
  3. What is the process to make the previous and next buttons on a CMS collection's pagination in Webflow scroll back to the top of the section?