Copied!
Guide

How to make a horizontal scroll section

The section that moves sideways while you scroll down is a tall wrapper, a sticky stage and one transform. Here is the pattern without ScrollTrigger, and the simpler CSS-only choice for a plain gallery.

← Blog
Title card: Horizontal scroll. Preview of the Horizontal scroll gallery element from the Enrichr Library.

December 4, 2026

3 min readSticky stage plus one transform

A horizontal scroll section moves its content sideways while the visitor scrolls down. To build one, make a wrapper that is much taller than the screen, pin a full-height stage inside it with position: sticky, and move the row of panels sideways according to how far the page has scrolled through the wrapper. You do not need ScrollTrigger for it.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

What is the code?

<section class="hs">
  <div class="hs-stage">
    <div class="hs-track">
      <article>One</article><article>Two</article><article>Three</article><article>Four</article>
    </div>
  </div>
</section>
.hs        { height: 400vh; }                 /* scroll length: 4 screens */
.hs-stage  { position: sticky; top: 0; height: 100vh; overflow: hidden; }
.hs-track  { display: flex; height: 100%; width: max-content; will-change: transform; }
.hs-track article { width: 100vw; height: 100%; }
const hs = document.querySelector(".hs");
const track = hs.querySelector(".hs-track");

function update() {
  const r = hs.getBoundingClientRect();
  const total = r.height - innerHeight;                       // scrollable distance
  const p = Math.min(1, Math.max(0, -r.top / total));         // 0 to 1
  const max = track.scrollWidth - innerWidth;                 // sideways distance
  track.style.transform = `translate3d(${-p * max}px, 0, 0)`;
}

let queued = false;
addEventListener("scroll", () => {
  if (queued) return;
  queued = true;
  requestAnimationFrame(() => { queued = false; update(); });
}, { passive: true });
addEventListener("resize", update);
update();

How do I set the speed?

With the height of the wrapper. In the example, 300 extra screen heights of scrolling move the track three screens sideways, so one scroll down equals one screen across. Make the wrapper taller for a slower, heavier feel. A neat rule is to set the wrapper height from the track width in JavaScript so the two always match.

Why does my stage not stick?

Check every ancestor for an overflow value other than visible. A common culprit is overflow-x: hidden on a page wrapper, added to stop sideways scrollbars. Use overflow-x: clip instead, which hides the overflow without creating a scroll container.

Is there a simpler way for a gallery?

.row { display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; }
.row > * { flex: 0 0 80%; scroll-snap-align: center; }

This is a real sideways scroller. It works with touch, trackpads, the keyboard and screen readers with no JavaScript. Use it when the visitor should be in control. Use the pinned pattern when the sideways move is part of a story.

Which finished examples can I copy?

ElementWhat it does
Snap sections horizontalA pinned stage that slides a row of sections sideways as you scroll down, easing to a stop on each.
Horizontal scroll galleryA row of cards that moves sideways with the wheel, a drag or the arrow keys.
Horizontal scroll colour morphA pinned band where scrolling slides one huge line of type sideways.
Sideways scroll lettersA huge line of text slides across while each letter arrives tossed and tilted.

All are free in the Enrichr Library, with a live demo and copyable code.

Where to go next

FAQ

How do I scroll horizontally when the user scrolls vertically?

Pin a stage with position: sticky inside a tall wrapper. As the page scrolls through the wrapper, set translateX on the row inside the stage in proportion to how far through you are.

Why is position sticky not working?

An ancestor has overflow: hidden, auto or scroll. Sticky positioning sticks to the nearest scrolling ancestor, so any of those on a parent stops it from sticking to the page.

Is horizontal scrolling bad for usability?

It can be. People expect the wheel to move the page down. Keep the section short, show that there is more to the side, and make sure every item can also be reached with the keyboard.

How do I make it work on phones?

The sticky pattern works with touch scrolling as it is. Many sites switch to a normal vertical stack on narrow screens, which is often the better choice.