How can I make the pagination in Swiper.js work in my Webflow project? I have tried both the progress bar pagination and the bullet style pagination, but neither of them is functioning. Can someone please help me identify where I went wrong?

TL;DR
  • Ensure your pagination element exists in Webflow and its class matches the Swiper config.  
  • Initialize Swiper after the DOM loads with correct settings (e.g., pagination.el, type, clickable).  
  • Include Swiper CSS in the site’s head and JS before the closing </body> tag.  
  • Avoid conflicts with Webflow’s native slider by using unique class names.  
  • Use browser dev tools to check for missing elements, JS errors, or uninitialized Swiper.

If pagination in Swiper.js isn't working in your Webflow project, the issue is typically related to incorrect initialization, missing configuration, or mismatched DOM selectors.

1. Verify Structure and Class Names in Webflow

  • Ensure elements exist for pagination: You must have a visible element in your Webflow design with the correct class (e.g., .swiper-pagination).
  • Match the class names in your Webflow elements to what you're targeting in JavaScript. For instance, if your pagination element has a class of swiper-pagination, your config must reference that same class.

2. Check Swiper Initialization Code

  • Confirm that you're initializing Swiper with the correct options. Here's how it should look without HTML:

  • For bullet pagination:
    • pagination.el must match your Webflow selector (e.g., .swiper-pagination)
    • pagination.type should be 'bullets'
    • clickable: true if you want interactive bullets

  • For progress bar:
    • Change pagination.type to 'progressbar'

  • Example (for bullets):

  ```js

  const swiper = new Swiper('.swiper', {

    pagination: {

      el: '.swiper-pagination',

      clickable: true,

      type: 'bullets',

    },

  });

  ```

  • Important: You must run this after the DOM is fully loaded. Either:
  • place it in a Page Load > Footer custom code block in Webflow,
  • or wrap it in Webflow.push(function() { ... })

3. Load Swiper Library Correctly

  • Ensure you have both the Swiper CSS and Swiper JS files properly included in your Webflow settings.
  • CDN links (latest version as of early 2024):
    • CSS: https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css
    • JS: https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.js

  • Add the CSS in Site Settings > Custom Code > Head
  • Add the JS in Site Settings > Custom Code > Before </body> tag or in your project page’s Footer

4. Avoid Conflicting Scripts

  • Webflow’s native slider might conflict with Swiper if both are on the same page.
  • Ensure only one instance of Swiper is targeting a specific container.
  • Use unique class names for Swiper elements to avoid clashes with other components.

5. Inspect with Dev Tools

  • Open your browser’s dev tools and check for:
  • JS errors in the console (e.g., swiper is not defined)
  • The presence of .swiper-pagination in the DOM
  • Missing Swiper CSS causing styles not to render (no visible bullets)

Summary

To fix pagination in Swiper.js within Webflow, you must (1) ensure your pagination element exists and matches your config, (2) properly configure the Swiper initialization with the correct type (bullets or progressbar), and (3) include all required Swiper CSS/JS files after the DOM is loaded. Double-check selectors and load timing in your custom code to ensure everything initializes correctly.

Rate this answer

Other Webflow Questions