Using Swiper Breakpoints for Responsive Slides-Per-View
Swiper breakpoints change slidesPerView and spacing by viewport width without breaking loop mode or pagination.
28 Jun 2026, 20:20 UTC

Your product slider shows one slide on phones, but the design calls for two on tablets and four on desktops. A common instinct is to use CSS media queries to hide extra slides or adjust widths, but Swiper calculates positions based on the DOM it sees. Hiding slides with CSS often leaves misaligned pagination, broken loop clones, or blank space where slides should be.
The practical fix is Swiper's breakpoints parameter. It changes functional settings—slidesPerView, spaceBetween, slidesPerGroup—when the viewport crosses pixel thresholds you define, without reinitializing the instance.
Breakpoint Logic and Module Registration
Swiper evaluates breakpoints mobile-first. The base configuration applies to every screen, and each numeric key overrides parameters when window.innerWidth is greater than or equal to that value. Larger keys override smaller ones cumulatively.
In an ES module build, you must import and register every module your breakpoints depend on. If Navigation or Pagination is missing from the modules array, breakpoint-dependent UI can fail silently or throw during initialization.
import Swiper from 'swiper';
import { Navigation, Pagination } from 'swiper/modules';
import 'swiper/css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
const swiper = new Swiper('.hero-slider', {
modules: [Navigation, Pagination],
// Base: mobile
slidesPerView: 1,
spaceBetween: 12,
slidesPerGroup: 1,
loop: true,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// Responsive overrides
breakpoints: {
640: {
slidesPerView: 2,
spaceBetween: 20,
slidesPerGroup: 2,
},
1024: {
slidesPerView: 4,
spaceBetween: 30,
slidesPerGroup: 4,
},
},
});
With this map, a phone sees one slide. At 640px the slider shows two and advances two slides per navigation click. At 1024px it shows four. Swiper recalculates slide widths and pagination bullets automatically when the viewport crosses those thresholds.
Limitations to Check Before Shipping
- Window width, not container width. Breakpoints compare against
window.innerWidth. If your slider lives inside a collapsible sidebar and the sidebar resizes without a window resize, Swiper will not re-evaluate. Callswiper.update()after the container change. - Loop compatibility. With
loop: true, changingslidesPerViewacross breakpoints can produce blank slides if the slide count is too low for the largestslidesPerView. Keep total slides well above your maximum breakpoint value, or disable loop for specific breakpoints. - Version differences. Breakpoint syntax and behavior differ between Swiper major versions. Test against the exact npm version you plan to deploy; do not assume v6 examples work in v11.
Verifying the Override
Open browser dev tools, locate your Swiper instance, and log the active parameter while resizing:
console.log(swiper.params.slidesPerView);
The value should change from 1 to 2 at 640px and from 2 to 4 at 1024px. If it stays static, confirm the breakpoint keys are numbers, the modules are registered, and nothing is forcing a fixed container width that bypasses Swiper's resize observer.
Breakpoints are the right tool when the slider's behavior—not just its appearance—must change by screen size. Pair them with swiper.update() for container-driven layouts, and test each breakpoint on the shipped package version.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.