Webflow sync, pageviews & more.
NEW

How can I style the second, third, and fourth slides after the currently active slide in the Webflow Slider using CSS or JavaScript?

TL;DR
  • Assign unique classes to each slide in Webflow, then use JavaScript to detect the active slide and add custom classes to the next 3 slides (e.g., after-1, after-2, after-3).
  • Apply corresponding CSS styles to those classes, and optionally handle looping with modular indexing for seamless transitions.

To style the second, third, and fourth slides after the currently active slide in a Webflow Slider, you'll need to use custom JavaScript—Webflow’s native slider component doesn’t provide built-in classes for those specific slide positions.

1. Understand How Webflow Slider Works

  • Webflow’s Slider gives the currently visible slide a class of w-slide-active.
  • All other slides are present in the DOM but don’t get position-related classes—so you'll need JavaScript to detect their order.
  • Slides are typically inside a div.w-slider-mask.

2. Add Unique Classes to Each Slide

  • In the Webflow Designer, select each slide and give them unique classes or combo classes (e.g., my-slide).
  • This will help in targeting them later via JavaScript.

3. Use JavaScript to Target Specific Slides After Active

Add the following JavaScript inside a Before custom code embed in your Page Settings or inside an Embed element in the Designer:

<script>  document.addEventListener("DOMContentLoaded", function () {    const slider = document.querySelector('.w-slider');    const slides = Array.from(document.querySelectorAll('.my-slide'));    function updateSlideClasses() {      // Clear all custom states first      slides.forEach(slide => {        slide.classList.remove('after-1', 'after-2', 'after-3');      });      const activeIndex = slides.findIndex(slide => slide.classList.contains('w-slide-active'));      if (activeIndex !== -1) {        // Add custom classes to 2nd, 3rd, and 4th slides after active        if (slides[activeIndex + 1]) slides[activeIndex + 1].classList.add('after-1');        if (slides[activeIndex + 2]) slides[activeIndex + 2].classList.add('after-2');        if (slides[activeIndex + 3]) slides[activeIndex + 3].classList.add('after-3');      }    }    // Listen for slide changes    const observer = new MutationObserver(updateSlideClasses);    const target = document.querySelector('.w-slider');    observer.observe(target, { childList: true, subtree: true });        // Initial call    updateSlideClasses();    // Or also bind to Webflow slider events (optional redundancy)    $('.w-slider').on('slid.bs.carousel', function () {      updateSlideClasses();    });  });</script>

4. Style with Custom CSS

In your Page Settings > Inside