ScrollPremium

Horizontal Scroll Track

You scroll down, the cards leave to the left: a track of five 180 px cards, pinned in the middle of a 280 px frame, slides 364 px during 520 px of scrolling and stops when the last card meets the right edge. The CSS works out the distance by itself; a 1 KB script replays the slide in Firefox.

CSSJSHorizontalScroll

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Scroll has 74 effects, including 12 free. Explore the category →

3 usage examples

A street of craft workshops, door by door — open-studio day of a craft quarter — Horizontal Scroll Track example 1

① A street of craft workshops, door by door — open-studio day of a craft quarter

WhenPage of an open-studio day: eight workshops on one street (bookbinding, ceramics, stained glass, clockmaking…), each with its number, its trade and the time of its demonstration.
WhyA street is walked from left to right: moving the shopfronts along while you go down the page tells the stroll with no carousel and no arrows. The track stops by itself on the last workshop whatever their number: adding a ninth exhibitor takes no setting at all.
SettingsA 540 × 308 px area, a 900 px tray (592 px of travel), eight 152 × 188 px cards drawn as shopfronts: a 1,350 px track, 810 px of slide. As the cards exceed half the frame, the track gets margin-bottom: -40px (see the FAQ). In the capture the area moves on its own at 150 px/s: a timer in the scene.
Signing up to a fencing club on a phone — the step strip slides as the form is filled in — Horizontal Scroll Track example 2

② Signing up to a fencing club on a phone — the step strip slides as the form is filled in

WhenA six-step sign-up form filled in on a phone: fencer, medical certificate, weapon, time slot, equipment, payment. The six step chips do not fit in 254 px of width.
WhyThe track becomes a step strip stuck to the top of the screen: as the form moves up, the strip slides and the current step stays in view, with nobody having to scroll it sideways. The effect stays a small 54 px detail; the main content is the form.
SettingsA 254 × 316 px area, the tray as tall as the form (880 px of travel), a 752 × 54 px track pinned with top: 27px (half its height), six 112 px chips: 498 px of slide. The current chip is coloured by a few lines of script that belong to the scene; the slide itself comes from the sold code. Scrolling at 170 px/s by the scene's timer in the capture.
The five evenings of a storytelling festival — one button per evening — Horizontal Scroll Track example 3

③ The five evenings of a storytelling festival — one button per evening

WhenProgramme of a five-evening festival: a row of five buttons (Wed 9 to Sun 13) above one large card per evening, with the show, the venue and the price.
WhyEach button sends the area to a quarter of its travel, and the chosen evening's card settles in the centre with its neighbours peeking on either side. The trip is smooth thanks to the scroll-behavior: smooth of the sold code. It remains real scrolling: the wheel and the arrow keys go through the five evenings too.
SettingsA 540 × 262 px area with no visible scrollbar, a 662 px tray (400 px of travel), five 300 × 218 px cards, 120 px of track padding: 1,264 px of slide, i.e. 316 px per button (one card and its gap). Track with margin-bottom: -90px. In the capture a timer clicks the buttons every 1.05 s.

How it works

Three nested boxes under .fx-0564-root. The .sdc-scroll-container area (280 px tall, 640 px wide at most) scrolls vertically. The .sdc-horiz-content tray, 800 px tall, is only there to give 520 px of travel; it trims what sticks out with overflow: clip, which does not create a scroll container. The .sdc-horiz-track track is position: sticky; top: 50% with a translateY(-50%): it stays centred in the frame (top at 70 px) while the tray goes by.

The slide is one keyframe, fx0564Glisse, wired to animation-timeline: scroll(). Its end state reads translateX(min(0px, calc(100cqw - 100%))): 100% is the track's width (it is width: max-content, 1,004 px for five cards), 100cqw the tray's, declared container-type: inline-size. The difference is exactly what overflows. Measured: −84 px at 120 px of scrolling, −182 px midway, −364 px at the end in a 640 px frame; −614 px in a 390 px frame. With eight cards and no CSS change: −952 px, last card 20 px from the right edge.

The motion is linear and reversible: scrolling back up brings the cards back. If the track already fits the frame (two cards, 416 px), min() keeps 0 and nothing moves. For browsers without animation-timeline, the script that ships with it puts the same keyframe on the track in a paused state and sets its currentTime on every scroll event; it looks up its elements root by root, so two copies stay independent (the second at 520 px, the first at 0). In Firefox 151 it yields the same positions as the CSS does in Chromium, to the pixel.

Accessibility

  • Reduced motion: content that leaves sideways while you scroll down is precisely what prefers-reduced-motion asks you to avoid. In that mode the code drives nothing: the track lies flat (position: static, no animation), the area switches to native horizontal scrolling with 364 px to cover, the “Scroll ↓” hint is hidden and the fallback script stops at its second test. Flat track and 364 px of horizontal scrolling read in all three engines.
  • Keyboard: the area takes focus (tabindex="0", role="region", aria-label) with a 2 px violet outline. The up and down arrows slide the track: four presses, 160 px of scrolling in Chromium, 204 px in Firefox. The cards are not links. Mind what happens if you make them links: tried in all three engines, Tab also reaches the fourth and the fifth, but the area does not scroll to show them — focus lands on a card outside the frame. You will then have to scroll the area yourself on focusin.
  • Reading: the five cards are in the HTML in track order. A screen reader reads them all, including those still outside the frame on the right. The pictograms are decorative (aria-hidden). The second line of each card sits at 7.1:1 on the card background.
  • Touch: the finger scrolls the area vertically, like the wheel — a 150 px drag, 149 px of scrolling in Chromium emulation. Swiping sideways does nothing, except in reduced motion where the track is indeed browsed sideways. That is counter-intuitive for a row of cards: keep a visible hint.

Browser compatibility

The native slide needs animation-timeline: scroll(): Chrome and Edge 115, Safari 26, Firefox 159 per MDN. cqw units and overflow: clip are older (Chrome 105, Safari 16, Firefox 110). Measured: Chromium 149 and WebKit 26.5 through the CSS (WebKit stops at −368 px, its scrollbar eats 4 px of frame); Firefox 151 through the fallback script, same values as Chromium.

Chrome 115+✓ Full, CSS only (measured in Chromium 149)
Edge 115+✓ Not verified (same engine as Chrome)
Safari 26+✓ Full in the WebKit 26.5 test build; real Safari not verified
Firefox 110 to 158✓ Full through the fallback script (measured in Firefox 151 only)
Firefox 159+✓ Not verified (native CSS announced by MDN, the script steps aside by itself)
iOS 26+ / Android Chrome 115+✓ Not verified on a device (drag measured in emulation)

The fallback script tests CSS.supports('animation-timeline', 'scroll()') and does nothing when the answer is yes. Otherwise it replays the CSS keyframe: the distance is still worked out by min() and cqw, nothing is duplicated in JavaScript. Without the script, a browser lacking animation-timeline shows a motionless track, the first cards visible and the others cut off.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0564-root">
  <div class="sdc-scroll-container" tabindex="0" role="region" aria-label="…">
    <div class="sdc-horiz-content">
      <div class="sdc-horiz-track">
        <div class="sdc-horiz-card">
          <div class="sdc-horiz-card-icon" style="background:…">
            <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">…</svg>
          </div>
          <h4>…</h4>
          <p>…</p>
        </div>
        … ×5
      </div>
    </div>
  </div>
  <span class="sdc-scroll-hint" aria-hidden="true">…</span>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Number of cards (HTML — .sdc-horiz-card) 5 cards, a 1,004 px track Add or remove cards without recomputing anything: eight cards slide 952 px and stop at the same spot, 20 px from the right edge. Below the frame's width the track stays still.
Frame width (CSS — .sdc-scroll-container { max-width: 640px }) 640 px at most, centred Widen it only if the track still overflows. Tried with no cap on a 1,280 px screen: the five cards fit the frame, the slide is 0 and you scroll 520 px for nothing.
Travel (CSS — .sdc-horiz-content { height: 800px }) 800 px, i.e. 520 px of scrolling for 364 px of slide The ratio of the two sets the apparent speed. Tray height = frame height + overflowing width: the track then moves one pixel per scrolled pixel. height: auto if the tray holds content.
Card height (CSS — .sdc-horiz-card { height: 140px }) 140 px, half the frame Beyond half the frame, the pinned track no longer fits the tray at the end of the travel and moves up. Make up for it with a negative margin-bottom on the track: card height minus half the frame (−60 px for 200 px).
Pinning notch (CSS — .sdc-horiz-track { top: 50% }) middle of the frame The keyframe keeps the translateY(-50%). To stick the track to the top, give top half the track's height (27 px for 54 px) rather than 0.
Fallback script (JS — 1 KB) included, active only without animation-timeline Remove it if a motionless track is fine for you in Firefox before 159. If you rename the fx0564Glisse keyframe, rename it in the el.style.animation line as well.
Hint (HTML — span.sdc-scroll-hint) “Scroll ↓” Here the hint earns its place: nothing about a row of cards says you should scroll down. Keep it or swap it for a marker of your own.

FAQ

Same idea, built another way. Horizontal Scroll Section names its timeline (scroll-timeline: --hscrollTimeline), pins a solid block as tall as the frame and translates the track by −75% of its width; in Firefox its fallback CSS lays the track flat. Here the timeline is anonymous (scroll(), the nearest scrolling ancestor), the track is a row of cards centred in the frame, the distance is computed to end on the last card, and Firefox gets the same slide through a script. Pick this one for a row of cards whose number changes; the other for large panels without a line of JavaScript.
First its width: if all the cards fit the frame there is nothing to slide and min(0px, …) returns 0 — measured with two cards (416 px in 640). Then the scrolling ancestor: scroll() takes the first one it finds, so a box with overflow: auto or hidden slipped between the area and the track becomes the timeline, and it does not scroll. That is why the tray uses overflow: clip.
A sticky element cannot leave its parent. With top: 50% the track's box starts at the middle of the frame: if it is more than half a frame tall, it runs into the bottom of the tray at the end of the travel. Measured with 200 px cards: the track climbs 60 px over the last 60 pixels. margin-bottom: -60px on the track (card height minus half the frame) fixes it, checked: it stays 40 px from the top all the way.