Strips of photographic film negatives coiled inside a tin

CSS timeline-scope: Link Two Carousels With a Single Scroll

Picture a product page where a customer swipes through a row of photos and, as they do, a second panel beside it glides along to show the matching price and details. No JavaScript listeners, no animation library, just CSS. That is exactly what the timeline-scope property makes possible, and it is one of the more useful additions to scroll-driven animation so far.

A reel of red film unspooling beside a vintage film reel

What problem does timeline-scope solve?

Scroll-driven animations let the position of a scrollbar, rather than a clock, control how far an animation has progressed. You name a scroll timeline on a scrolling element, and then an element that is allowed to see that timeline uses it to drive its keyframes.

The catch is visibility. By default, a named timeline can only be used by the element that defines it and that element’s descendants. A neighbouring element, which is often exactly what you want to animate, cannot see it at all.

timeline-scope removes that restriction. You declare the timeline name on a shared ancestor, and from then on any element inside that ancestor can use the timeline, wherever it sits in the markup. One scroll, many animated elements.

Go Ad Free

How do you link two carousels together?

Start with two simple pieces of markup: a primary carousel the visitor scrolls, and a secondary one that only moves in response. The secondary carousel does not need its own scrollbar, so its overflow is simply clipped.

.primary {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.primary li {
  scroll-snap-align: center;
}

.secondary {
  overflow: clip;
}

Next, write the keyframes for the secondary carousel. It needs to slide left by one slide’s width for every step the primary carousel takes. The new sibling-count() function helps here, because it works out how many slides there are without you hard-coding a number.

@keyframes slide-along {
  to {
    transform: translateX(calc(-100% * (sibling-count() - 1)));
  }
}

There is no duration to set. When an animation is tied to a scroll timeline, its progress comes from the scroll position, so the animation simply plays forwards as the visitor scrolls forwards, and backwards when they scroll back.

Two blank film frames with dark sprocket edges

Where does the timeline-scope line go?

Name the scroll timeline on the primary carousel, then attach the secondary slides to that same name. On their own, those two declarations would not connect, because the secondary slides cannot see a timeline owned by a sibling.

.primary {
  scroll-timeline: --carousel-scroll x;
}

.secondary li {
  animation: slide-along linear forwards;
  animation-timeline: --carousel-scroll;
}

/* The shared parent makes the timeline visible to both */
body {
  timeline-scope: --carousel-scroll;
}

The body here is only there because it is the nearest ancestor both carousels share. In a real page you would normally put the declaration on a wrapper such as a .carousels container, so the scope stays tight. You can also attach as many extra elements as you like to the same timeline, and each one can run a completely different animation.

Is it safe to use on a client site today?

Not for anything essential. timeline-scope is not yet part of Baseline, meaning it does not work consistently in every major browser, and sibling-count() is still rolling out too. Treat both as polish for decorative parts of a page and make sure the content is perfectly usable without them.

Go Ad Free

Motion deserves care as well. Anything that moves in response to scrolling should respect the prefers-reduced-motion setting, and carousels should always offer a way to move between slides that does not depend on scrolling gestures, such as buttons or keyboard controls.

Scattered film strips showing small colour slides on a white background

For small business owners, the takeaway is that engaging, interactive-feeling product galleries no longer need heavy scripts that slow a site down. Whether your customers browse from Jávea or Manchester, lighter pages load faster on mobile connections, and that helps both sales and search rankings. If you are planning a refresh of your product pages, it is worth asking your developer whether effects like this could replace some of your existing scripts. Where would a little scroll-linked movement help your visitors most?

Go Ad Free

Create a free account, or log in.

Gain access to read this article, join developers who build better, faster, smarter solutions

Yes! I would like to receive new content and updates.

Scroll to Top