Skip to content

Responsive Gallery

A common need is showing several slides on desktop but fewer on mobile. Splide’s breakpoints option overrides any options below a given screen width, so a single slider adapts as the viewport shrinks.

pages/gallery.vue
<template>
<Splide :options="options" aria-label="Photo gallery">
<SplideSlide v-for="photo in photos" :key="photo.id">
<img :src="photo.src" :alt="photo.alt">
</SplideSlide>
</Splide>
</template>
<script setup lang="ts">
const options = {
type: 'loop',
perPage: 4,
perMove: 1,
gap: '1rem',
pagination: true,
arrows: true,
breakpoints: {
1024: { perPage: 3 },
768: { perPage: 2 },
480: { perPage: 1, arrows: false },
},
}
const photos = [
{ id: 1, src: '/gallery/1.jpg', alt: 'Mountains at dawn' },
{ id: 2, src: '/gallery/2.jpg', alt: 'A quiet lake' },
{ id: 3, src: '/gallery/3.jpg', alt: 'City skyline' },
{ id: 4, src: '/gallery/4.jpg', alt: 'Desert dunes' },
{ id: 5, src: '/gallery/5.jpg', alt: 'Forest trail' },
{ id: 6, src: '/gallery/6.jpg', alt: 'Coastal cliffs' },
]
</script>
<style>
img {
width: 100%;
aspect-ratio: 3 / 2;
object-fit: cover;
border-radius: 0.5rem;
}
</style>

breakpoints is keyed by maximum width in pixels — each entry applies at or below that width. With the config above:

Viewport widthSlides shown
> 1024px4 (the base perPage)
≤ 1024px3
≤ 768px2
≤ 480px1 (and arrows hidden)

Any option can be overridden per breakpoint, not just perPage — here arrows are turned off on the smallest screens.