7.3 · Forms & UI
Carousels in CSS: scroll markers and buttons
Dots and arrows for a scroll container, generated by CSS.
A scroll container can generate its own controls.
scroll-marker-group: after adds a row of
::scroll-marker dots, one per item, that scroll to their
item when clicked. :target-current styles the active one.
::scroll-button(inline-start) and
::scroll-button(inline-end) add previous and next buttons
that disable themselves at the ends. They are real buttons, focusable
and accessible.
// A carousel library, or:
dots.forEach((dot, i) => dot.onclick = () =>
slides[i].scrollIntoView())
new IntersectionObserver(updateActiveDot)
prev.onclick = () => scroller.scrollBy(…)
.carousel {
scroll-snap-type: x mandatory;
scroll-marker-group: after;
}
li::scroll-marker { content: ''; }
li::scroll-marker:target-current { … }
.carousel::scroll-button(inline-end) {
content: '→' / 'Next';
}