Progress dots pager
Carousel pager in HTML, CSS and JS: dots where the active one stretches into a bar that fills over five seconds, plus a pause button.
The timer is a CSS animation. The active dot widens to 32px and its ::after layer animates transform: scaleX from 0 to 1 over five seconds, and the script listens for animationend to move to the next dot, wrapping at the end. Clicking a dot calls the same function, which re-adds is-active after a forced reflow so the animation restarts, and the pause button toggles a data-paused attribute that pauses the animation and updates aria-pressed and aria-label. The dots are buttons with role=tab and aria-selected, the script finds the pager by id so it suits one per page, and it does not change any slides.
snippet.html56 lines
<div class="pdp" id="pdp">
<div class="pdp__dots" role="tablist" aria-label="Slides">
<button class="pdp__dot is-active" type="button" role="tab" aria-selected="true" aria-label="Slide 1"></button>
<button class="pdp__dot" type="button" role="tab" aria-selected="false" aria-label="Slide 2"></button>
<button class="pdp__dot" type="button" role="tab" aria-selected="false" aria-label="Slide 3"></button>
<button class="pdp__dot" type="button" role="tab" aria-selected="false" aria-label="Slide 4"></button>
<button class="pdp__dot" type="button" role="tab" aria-selected="false" aria-label="Slide 5"></button>
</div>
<button class="pdp__pause" type="button" aria-label="Pause autoplay" aria-pressed="false">
<svg viewBox="0 0 16 16" aria-hidden="true"><path class="pdp__ic-pause" d="M5 3h2v10H5zm4 0h2v10H9z" fill="currentColor"/><path class="pdp__ic-play" d="M5 3l8 5-8 5z" fill="currentColor"/></svg>
</button>
</div>
<style>
.pdp { display: inline-flex; align-items: center; gap: 0.75rem; font-family: ui-sans-serif, system-ui, sans-serif; }
.pdp__dots { display: flex; align-items: center; gap: 0.5rem; padding: 0.8rem 1rem; border-radius: 999px; background: rgba(210, 210, 215, 0.64); backdrop-filter: blur(20px); }
.pdp__dot { position: relative; width: 8px; height: 8px; padding: 0; border: 0; border-radius: 999px; background: rgba(0, 0, 0, 0.42); cursor: pointer; overflow: hidden; transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s; }
.pdp__dot::after { content: ""; position: absolute; inset: 0; background: #1d1d1f; transform: scaleX(0); transform-origin: left; }
.pdp__dot.is-active { width: 32px; }
.pdp__dot.is-active::after { animation: pdp-fill 5s linear forwards; }
.pdp[data-paused] .pdp__dot.is-active::after { animation-play-state: paused; }
.pdp__dot:focus-visible, .pdp__pause:focus-visible { outline: 2px solid #0071e3; outline-offset: 3px; }
.pdp__pause { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: rgba(210, 210, 215, 0.64); color: #1d1d1f; cursor: pointer; }
.pdp__pause svg { width: 14px; height: 14px; }
.pdp__ic-play { display: none; }
.pdp[data-paused] .pdp__ic-play { display: block; }
.pdp[data-paused] .pdp__ic-pause { display: none; }
@keyframes pdp-fill { to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) { .pdp__dot { transition: none; } .pdp__dot.is-active::after { animation: none; transform: scaleX(1); } }
</style>
<script>
(function () {
var root = document.getElementById("pdp");
if (!root) return;
var dots = Array.prototype.slice.call(root.querySelectorAll(".pdp__dot"));
var pause = root.querySelector(".pdp__pause");
var cur = 0;
function go(i) {
cur = (i + dots.length) % dots.length;
dots.forEach(function (d, n) {
d.classList.remove("is-active");
d.setAttribute("aria-selected", n === cur ? "true" : "false");
});
void root.offsetWidth;
dots[cur].classList.add("is-active");
}
dots.forEach(function (d, n) { d.addEventListener("click", function () { go(n); }); });
root.addEventListener("animationend", function () { if (!root.hasAttribute("data-paused")) go(cur + 1); });
pause.addEventListener("click", function () {
var p = root.toggleAttribute("data-paused");
pause.setAttribute("aria-pressed", p ? "true" : "false");
pause.setAttribute("aria-label", p ? "Play autoplay" : "Pause autoplay");
});
})();
</script>