Slider
A native horizontal scroller with CSS scroll-snap - swipe, trackpad and keyboard work without any script.
varz-slider.js (3.8 kB minified + gzipped) adds arrows, dots, mouse drag, autoplay with a pause button, loop and accessible labels.
One slide, autoplay, loop
Several slides in view
Slides out of view are dimmed with --o:.55;--vz-o:1 - the script adds .vz to the slides in view.
Control looks
Generated controls (data-vz-controls) in six dot looks and four arrow looks - bar puts the arrows next to the dots.
data-vz-dots="pill" data-vz-arrows="round"data-vz-dots="round" data-vz-arrows="square"data-vz-dots="square" data-vz-arrows="outline"data-vz-dots="line" data-vz-arrows="plain"data-vz-dots="ring" data-vz-arrows="round bar"data-vz-dots="number" data-vz-arrows="outline bar"CSS only (no script)
The same track without data-varz-slider: swipe, trackpad or Shift + mouse wheel; visible scrollbar.
Markup
<div data-varz-slider data-vz-autoplay="5000" data-vz-loop aria-label="Featured">
<div data-varz-track style="--d:flex;--ox:auto;--sst:x mandatory;--sbw:none;">
<div style="--flb:100%;--fls:0;--ssa:start;">Slide 1</div>
<div style="--flb:100%;--fls:0;--ssa:start;">Slide 2</div>
</div>
<button type="button" data-varz-prev>‹</button>
<button type="button" data-varz-next>›</button>
<div data-varz-dots>
<button type="button" data-varz-dot hidden style="--bgc:gray;--vz-bgc:red;"></button>
</div>
<button type="button" data-varz-play hidden>...</button>
</div>
<script src="varz.js" defer></script>
<script src="varz-slider.js" defer></script>
| Attribute | On | What it does |
|---|---|---|
data-varz-slider | wrapper | Turns the block into a carousel (role region, aria-roledescription carousel). |
data-vz-autoplay="ms" | wrapper | Next slide every ms. Pauses on hover, focus and in hidden tabs; stops for good after a swipe or the pause button. Off with prefers-reduced-motion. |
data-vz-loop | wrapper | Arrows wrap around at the ends (autoplay always does). |
data-vz-controls="arrows,dots,play" | wrapper | Adds the controls the markup does not have, with default looks (varz.slider.styles) - a bare track becomes a full slider. |
data-vz-dots="pill" | wrapper | Look of generated dots: pill (default, the active one wider), round, square, line, ring, number. |
data-vz-arrows="round" | wrapper | Look of generated arrows: round (default), square, outline, plain; add bar to place them next to the dots. |
data-varz-dot-number | inside the dot template | Gets the dot's number (numbered dots in your own markup). |
data-varz-track | scroller | The scroll-snap container; its children are the slides (labelled "1 of 4"). Focusable: ← → keys. |
data-varz-prev / data-varz-next | button | Previous / next position, disabled at the ends without loop. |
data-varz-dots + data-varz-dot | container + template | One dot per reachable position (fewer than slides when several are in view). Active dot: .vz, aria-current. |
data-varz-play | button | Pause / play; shown only with autoplay; .vz while playing. |
.vz is added to the slides in view (style with --vz-*), events: varz-slide on the wrapper,
varz-activated / varz-deactivated on slides. Scroll props from VARZ: --sst scroll-snap-type, --ssa scroll-snap-align, --sbw scrollbar-width (responsive), --osb overscroll-behavior, --lst list-style, --foc-olo focus outline offset.