A lightweight, dependency-free JavaScript slider that leverages native browser scrolling for smooth, performant carousel experiences.
This slider leverages native browser overflow scrolling - no DOM manipulation required
Unlike other sliders, this library doesn't rewrite your DOM or add unnecessary markup. It works with a simple
overflow: auto container and enhances it with JavaScript controls. You keep full control over your
HTML structure and styling.
Natural scrolling behavior: Touch and mouse drag scrolling work exactly as they do in any native scrolling container - no hijacked events or custom touch handlers. The slider enhances native scroll behavior with navigation controls and additional features.
The demos below use custom gradient styles for visual appeal, but the slider works with any HTML content. Toggle the styles below to see the raw HTML structure:
Simple slider showing 3 slides at once with navigation buttons
const slider = new NativeScrollSlider(document.querySelector('#basic-slider .slider-track'), {
slidesToShow: 3,
slidesToScroll: 1,
gap: 20
});
Automatically advances slides every 3 seconds (pauses on hover)
const slider = new NativeScrollSlider(document.querySelector('#autoplay-slider .slider-track'), {
slidesToShow: 2,
autoplay: true,
autoplaySpeed: 3000
});
Seamlessly loops through slides for endless scrolling
const slider = new NativeScrollSlider(document.querySelector('#infinite-slider .slider-track'), {
slidesToShow: 3,
infinite: true,
autoplay: true
});
Centers the active slide with visual highlighting
const slider = new NativeScrollSlider(document.querySelector('#center-slider .slider-track'), {
slidesToShow: 1,
centerMode: true,
infinite: true
});
Adapts to different screen sizes with custom breakpoints
const slider = new NativeScrollSlider(document.querySelector('#responsive-slider .slider-track'), {
slidesToShow: 4,
responsive: [
{
breakpoint: 1200,
settings: { slidesToShow: 3 }
},
{
breakpoint: 992,
settings: { slidesToShow: 2 }
},
{
breakpoint: 768,
settings: { slidesToShow: 1 }
}
]
});
Peek at next/previous slides to indicate more content
const slider = new NativeScrollSlider(document.querySelector('#overflow-slider .slider-track'), {
slidesToShow: 2,
showOverflow: true,
overflowAmount: 0.3
});
Get started with Native Scroll Slider in your project
npm install native-scroll-slider
<script src="https://unpkg.com/native-scroll-slider/dist/native-scroll-slider.min.js"></script>
<div class="slider-container">
<div class="slider-track">
<div class="slide">Slide 1</div>
<div class="slide">Slide 2</div>
<div class="slide">Slide 3</div>
</div>
<button class="slider-prev">Previous</button>
<button class="slider-next">Next</button>
</div>
import NativeScrollSlider from 'native-scroll-slider';
const slider = new NativeScrollSlider(
document.querySelector('.slider-track'),
{
slidesToShow: 3,
autoplay: true
}
);
All available configuration options with their default values:
slidesToShow: 4 - Number of slides visible at onceslidesToScroll: 1 - Number of slides to scroll per navigationgap: 24 - Space between slides in pixelsstartSlide: 0 - Index of initial slide to showminSlideWidth: 0 - Minimum width for each slide in pixelsinfinite: false - Enable infinite/continuous scrollingbounceBack: false - Enable bounce-back animation at edgescenterMode: false - Center the active slideautoplay: false - Enable automatic slide advancementautoplaySpeed: 3000 - Autoplay interval in millisecondsshowOverflow: false - Show partial next/previous slidesoverflowAmount: 0.5 - Amount of overflow slide to show (0-1)containerMaxWidth: 1200 - Maximum container width in pixelsbasePadding: 35 - Base padding in pixels for overflow modeprevElement: '.prev, .slider-prev, .slider-grid-prev' - Selector for previous buttonnextElement: '.next, .slider-next, .slider-grid-next' - Selector for next buttonresponsive: [...] - Array of breakpoint configurations// Example responsive configuration
responsive: [
{
breakpoint: 1200,
settings: { slidesToShow: 3 }
},
{
breakpoint: 992,
settings: { slidesToShow: 2 }
},
{
breakpoint: 768,
settings: { slidesToShow: 1 }
}
]