A lightweight, CSS-first slider library for the modern web: about 7.8 KB for the core and 10.7 KB with every extension, JavaScript and CSS gzipped, with no dependencies.
- CSS-First Architecture — Layout via custom properties, responsive via media queries
- Native Scroll Snapping — Hardware-accelerated, smooth scrolling
- Continuous Autoplay —
autoplay: "continuous"drifts the track like a ticker atautoplaySpeedpx/s, seamlessly looped with no per-frame JavaScript - Snap Modes — Native CSS snapping by default;
snap: "settle"scrolls freely and eases onto the nearest slide,snap: "none"rests wherever it stops - Minimal JS Footprint — Only handles events, loop cloning, pagination, autoplay
- Zero Dependencies — No external libraries required
- Thumbnail Syncing — Link primary sliders with thumbnail navigation
- iOS-Style Pagination — Optional
maxDotsfor scrolling dots
Documentation: aeroslider.com
bun add aero-sliderOr with npm:
npm install aero-sliderThen import the package and styles:
import { createSlider, use, loop, autoplay } from "aero-slider";
import "aero-slider/slider.css";
use({ loop, autoplay }); // only the extensions you use end up in your bundleThe core covers slides, arrows, dots, keyboard, drag and snapping. Looping, autoplay, scrolling dots (maxDots) and thumbnail sync are extensions. Each one has its own file in dist/extensions/, so you can load only what you use, or concatenate the core and your extensions into one file.
Autoplay requires the loop extension. Autoplay, interval or continuous, always loops: setting autoplay turns looping on.
aero-slider/slider.css has the CSS for the core and every extension. To load only what you use, import the core stylesheet and your extensions' instead:
import "aero-slider/core.css";
import "aero-slider/extensions/loop.css"; // loop, autoplay
import "aero-slider/extensions/scrolling-dots.css"; // maxDotsAdd the JavaScript and CSS files. dist/aero-slider.min.js sets window.AeroSlider; load it with type="module":
<link rel="stylesheet" href="https://unpkg.com/aero-slider/dist/aero-slider.min.css" />
<script type="module" src="https://unpkg.com/aero-slider/dist/aero-slider.min.js"></script>Or download from the releases page. This creates a global AeroSlider object:
const slider = AeroSlider.createSlider(document.getElementById("my-slider"), { loop: true });
// With thumbnails:
const main = AeroSlider.createSlider(mainEl);
const thumbs = AeroSlider.createSlider(thumbsEl);
const teardown = AeroSlider.syncThumbnails(main, thumbs);The bundler entry (import ... from "aero-slider") sets no global, so bundlers can drop what you don't import.
aeroslider.md is a compact guide for coding agents: the markup to write, the CSS variables, options, instance, events, how to extend the slider and the accessibility split. Point your agent at node_modules/aero-slider/aeroslider.md or at aeroslider.com/aeroslider.md. It is also in every release zip, next to the JavaScript and CSS.
Roles, names and controls belong in your markup. The slider adds only what changes at runtime.
The slider does this:
- Makes the container the one tab stop. Arrow keys, Home and End move the slider while the container, a nav button or a dot has focus. Keys pressed inside slide content stay with that content.
- Marks the current dot, and the current thumbnail of a synced strip, with
aria-current="true". - Makes each thumbnail of a synced strip that isn't a control of its own a button: a tab stop with
role="button"that Enter and Space press, named "Go to slide N" when it has no name. The teardown takes all of it back. - Hides loop clones from screen readers, the tab order and forms.
- Keeps keyboard focus when a nav button disables or the dots are rebuilt, and brings a partly shown slide into view when focus moves into it.
- Announces the new position ("2 of 5") in a hidden live region when a user changes slide. It stays quiet for the moves autoplay makes on its own. Set
data-aero-status="Bild {index} von {count}"on the container to word it for another language.
You write this:
<div
class="aero-slider"
role="region"
aria-roledescription="carousel"
aria-label="Featured products"
>
<div class="aero-slider__viewport">
<button type="button" class="aero-slider__nav--prev" aria-label="Previous slide"></button>
<button type="button" class="aero-slider__nav--next" aria-label="Next slide"></button>
<div class="aero-slider__track">
<div role="group" aria-roledescription="slide" aria-label="1 of 3">…</div>
<div role="group" aria-roledescription="slide" aria-label="2 of 3">…</div>
<div role="group" aria-roledescription="slide" aria-label="3 of 3">…</div>
</div>
</div>
<div class="aero-slider__pagination" role="group" aria-label="Slides">
<button type="button" class="aero-slider__dot" aria-label="Go to slide {index}"></button>
</div>
</div>- Dots. The one dot in the markup is a template. Make it a
<button type="button">: a<span>is not reachable by keyboard.{index}in itsaria-labelbecomes each dot's slide number. - Thumbnails. Give each thumbnail of a synced strip its own name, such as an image's
alt. A<button type="button">or a link is left as it is. - Autoplay. Anything that moves for more than five seconds needs a pause control. Wire your own button to
pause()andresume():
const slider = createSlider(el, { autoplay: true });
let paused = false;
toggle.addEventListener("click", () => {
paused = !paused;
slider[paused ? "pause" : "resume"]();
toggle.setAttribute("aria-pressed", String(paused));
});Text inside a slide can't be selected while a mouse drag would move the slider; list it in noDrag (for example noDrag: "p, h2") to keep it selectable. noDrag defaults to "input, textarea, select, [contenteditable]", and your value replaces it. Video and audio with native controls are safe to drag, because browsers keep a press on the control bar inside their own controls. Firefox does not let a mouse drag a video with controls at all.
Types ship with the package. Slider events are typed on every HTMLElement, so listeners need no cast:
import { createSlider, type SliderEventMap } from "aero-slider";
createSlider(el);
el.addEventListener("aero:slideChange", (e) => console.log(e.detail.index));
type SlideChange = SliderEventMap["slideChange"]; // { index: number }1.1 needs no changes to your markup or CSS. One default is different:
noDragno longer listsaudio[controls]andvideo[controls], so a mouse drag can start on the picture of a video with native controls. Add them back (noDrag: "input, textarea, select, [contenteditable], audio[controls], video[controls]") if a press on a video must not drag.
1.0 renamed these, and the old names no longer work. Rename them in your options, markup and CSS:
| Beta | 1.0 |
|---|---|
alignment: "left" |
alignment: "start" |
alignment: "right" |
alignment: "end" |
--slides-per-view |
--aero-slides-per-view |
--slide-gap |
--aero-slide-gap |
--slide-aspect |
--aero-slide-aspect |
The betas also had these, which 1.0 removes:
| Beta | 1.0 |
|---|---|
slider.add(), slider.remove() |
Change the track's children, then call slider.refresh() |
direction: "ttb" |
vertical: true |
direction: "rtl" |
dir="rtl" on the slider or any ancestor |
labels |
Write the names in your markup |
More things to check:
- Roles and names are yours now. The betas wrote the roles and labels for the container, slides, arrows and dots. 1.0 leaves them to your markup, so add them as Accessibility shows. Without them the slider still works, but screen readers get unnamed controls.
- Finding slides in a looping slider. A looping track also holds copies of its slides. Select a real slide with
[data-aero-slider-index="2"], not by its place among the track's children. - Alignment is logical.
"start"is the right edge in an RTL slider and the top in a vertical one. - Your own selectors on
data-aero-alignment. The attribute now holds"start","center"or"end", so a rule such as[data-aero-alignment="left"]no longer matches. - Nested sliders. The
--aero-*variables are inherited, so you can set them on any ancestor of a slider. The exception is--aero-layout-width, which goes on the slider itself. They stop at the content of a slide: a slider nested inside a slide, or used as a slide itself, does not take the outer slider's settings, so set its variables on the nested slider itself.
See CONTRIBUTING.md for development setup, working on the doc site, and publishing.