CSS Carousels: Scroll Snap, Markers, and Buttons

CSS Carousels: Scroll Snap, Markers, and Buttons

The carousel library decomposed into CSS primitives: an interoperable scroll-snap floor, engine-generated markers and buttons on top, and an honest list of what still needs JS.

A carousel decomposes into a scroll container, a snapping rule, paging affordances, and an active-slide state — and CSS now covers all four, the last two so far only in Chromium browsers. Scroll snap is the interoperable floor that already delivers a usable swipe carousel everywhere; the generated ::scroll-marker and ::scroll-button pseudo-elements add pagination and prev/next controls where they are supported, which as of November 2026 means Chromium browsers (Chrome and Edge 135+). The correct architecture is enhancement-only: a functional scroll carousel in every engine, engine-generated controls layered on top, and an honest list of what still needs JavaScript.

What a carousel actually is

Strip the pattern to its parts and a carousel is four things: a container that scrolls through slides, a rule that makes scrolling settle on slide boundaries, affordances for paging — dots and prev/next buttons — and a way to style whichever slide is current. Nothing in that list inherently requires JavaScript anymore, although only Chromium browsers implement the last two in CSS so far.

JavaScript libraries owned the pattern because, until recently, the last two parts did require it — and once a library is managing buttons and state, it tends to take over the scrolling itself. That is where the costs concentrated: extra script weight on landing pages, scroll hijacking that can fight the user's own gestures and break on trackpads, and per-library ARIA wiring of varying quality, reimplemented slightly differently from one slider library to the next.

The scale of the deletion is documented. Pinterest, an early adopter, rebuilt its carousel on the new CSS primitives and replaced roughly 2,000 lines of JavaScript with roughly 200 lines of CSS, a 90% reduction reported in Google's I/O 2025 recap (accessed October 2026).

The scroll-snap foundation

The foundation layer is scroll snap, and it is worth building first because it works in all three engines today and already produces a usable carousel: swipeable on touch, draggable on trackpads, scrollbar-navigable, and keyboard-scrollable once the scroller itself or a slide inside it can take focus (test each engine).

css
.carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 80%;
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 1rem;
}

.carousel > * {
  scroll-snap-align: center;
}

Two decisions here are design decisions, not defaults. scroll-snap-type's mandatory strictness means the scroller always settles on a snap point — right for paged content like cards and photos; proximity is gentler for mixed content the user may want to stop mid-way through. And adding scroll-snap-stop: always to the slides, which the block above leaves out, turns free-momentum scrolling into one-slide-per-gesture paging, which suits product carousels that page one item at a time.

Contain the scrolling with overscroll-behavior-x: contain so a swipe past the last slide does not start navigating the page. Scroll snap itself is long-interoperable: web-features lists the feature as Baseline Widely available since July 2022, and scroll-snap-stop since January 2025 (MDN's scroll snap module documents the details). overscroll-behavior-x works on scrolling carousels in Chrome, Edge, Firefox, and Safari 16+, although web-features does not list it as Baseline as of November 2026 and BCD marks Safari's implementation as partial (no effect on scroll containers without scrollable overflow). This layer is the cross-browser floor, not an enhancement.

Slide layout patterns

The track itself is ordinary layout. Grid auto-flow columns, as above, is the workhorse: slide width comes from grid-auto-columns, and an 80% column with scroll-padding produces the peek-ahead affordance — a sliver of the next slide visible at the edge — that tells users the row scrolls without any control being rendered yet.

Multi-item pages fall out of the same declaration: grid-auto-columns: calc((100% - 2rem) / 3) shows three items per page, and start-edge snapping keeps every stop aligned to an item boundary — each item is its own snap position, so a swipe can settle mid-group. Use logical properties (inline-size, scroll-padding-inline, inset-inline) throughout so the track works unchanged in right-to-left interfaces.

Slides holding images need one more rule: a fixed aspect-ratio on the media box, so the track's height does not jump as images load. A carousel near the top of the page is a prime suspect for layout shift; reserving media space in CSS is cheaper than any later fix.

Markers: generated pagination

Pagination dots used to mean DOM bookkeeping: render a dot per slide, sync it on scroll, wire the clicks. The scroll-marker pseudo-elements move all of it into the engine.

css
.carousel {
  scroll-marker-group: after;
}

.carousel > *::scroll-marker {
  content: '';
  inline-size: 0.75rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--dot, #ccc);
}

.carousel > *::scroll-marker:target-current {
  background: var(--dot-active, #333);
}

scroll-marker-group: after tells the container to generate a marker group after the track; each slide's ::scroll-marker generates one marker inside it. The markers are real, focusable, activatable controls: clicking one scrolls to its slide, and :target-current styles the marker whose slide is currently snapped — the active state, with no scroll listener anywhere.

The accessibility dividend is the point to appreciate. The engine gives the marker group and its markers accessible roles (Chrome's carousel guide says the markers report like a tablist to screen readers), associates each marker with its slide, and handles focus behavior consistently — the wiring JavaScript carousels hand-built, each slightly differently, and a possible source of regressions when teams switched libraries.

Buttons: generated prev/next

The second affordance is the prev/next pair, generated the same way.

css
.carousel::scroll-button(inline-start) {
  content: '←' / 'Previous';
}

.carousel::scroll-button(inline-end) {
  content: '→' / 'Next';
}

Each ::scroll-button() is a real button the engine renders and operates: activating it scrolls one page in that direction, and — the detail that used to be bookkeeping — the engine automatically disables the button when the scroller reaches that end, updating its state as the user scrolls by any other means. The content alternative-text syntax ('→' / 'Next') keeps the visible glyph and the accessible name separate.

Buttons and markers are pseudo-elements, so they style and position like any other generated content — and positioning them against the carousel composes naturally with anchor-positioning concepts where a design wants buttons floated over the track's edges. What disappears is the wiring: the click handlers, the disabled-state logic, and the scrollTo math that slider libraries otherwise implement in their control code.

Support posture and honest limits

The gate, dated: the carousel pseudo-elements ::scroll-marker, ::scroll-marker-group, and ::scroll-button(), along with the :target-current pseudo-class, ship in Chrome and Edge 135+ and have not shipped in Firefox or Safari as of November 2026 (Chrome's carousel guide tracks the details; re-verify against MDN or Baseline at decision time). Single-engine means the posture is enhancement-only, without hedging.

The architecture that posture produces is the one this article has been building in order. The scroll-snap track is the product: every user in every engine gets a swipeable, scrollable carousel with peek-ahead affordances, and keyboard access is worth testing in each engine. The generated markers and buttons are layered polish that costs nothing where it is absent — unsupported engines simply do not render the pseudo-elements, and no @supports block is needed for controls that are pure additions. Where fallback markers are considered essential to the design, that is the signal this component is not ready to leave its JavaScript library yet — a designed decision, not a failure.

The honest limits, because deleting the library does not delete every requirement it served. Autoplay and rotation timers are not in the primitive, and the accessibility work comes with them: WCAG 2.2 Success Criterion 2.2.2 Pause, Stop, Hide (Level A) requires a mechanism for the user to pause, stop, or hide moving, blinking, or scrolling information that starts automatically, lasts more than five seconds, and is presented in parallel with other content, unless the movement, blinking, or scrolling is part of an activity where it is essential. Honoring reduced-motion preferences is a further design choice on top of that. Infinite looping is not expressible with scroll snap. Per-slide analytics events still need JavaScript — an IntersectionObserver, or in Chromium browsers (Chrome and Edge 129+, as of November 2026) the scrollsnapchange event. Virtualizing a thousand-slide track is still an engineering problem. A carousel needing several of those keeps its library; a carousel needing none of them can delete it.

One boundary sentence for completeness: scroll-driven motion effects — parallax, scroll-linked reveals, reading-progress indicators — are a different mechanism with their own patterns and their own reduced-motion contract; everything scroll-related in this article is component plumbing, not motion design.

Project Inquiry