Horizontal Scroll Sections
Updated 2026-10-16. 8 effects.
A horizontal scroll section turns downward scrolling into sideways movement: the section pins with position: sticky while a wide row inside it translates left in step with scroll progress. The simpler kind is a row with overflow-x: auto and scroll-snap-type that people swipe or drag. Both kinds are here.
Choose the pinned kind for a short, ordered sequence, such as a process, a timeline or a set of chapters, where moving sideways adds a sense of travel. Choose the snap row for browsing, such as products, case studies or photos, where people want to go at their own pace and skip ahead.
Pinned rows hijack nothing: the page still scrolls normally, and the sideways distance is set by the height of the section, so it always ends. Keep them short. On phones, and when reduced motion is on, the pieces here become an ordinary swipeable row or a vertical list.
Compare them
| Effect | Built with | Size (gzipped) | Running cost | Browser support |
|---|---|---|---|---|
| Drag to Scroll Weekly Timetable Row with Snap | CSS and a small script | 3.1 KB | Drag writes scrollLeft only while a mouse button is held; otherwise the row is native scrolling with snap. | All current browsers |
| Full Width Snap Slides with Project Name Tabs | CSS only | 3.2 KB | Native snap scrolling with one scroll listener that only touches the DOM when the slide in view changes. | All current browsers |
| Pinned Boat Restoration Timeline Drawing Sideways | CSS and a small script | 3.8 KB | Two transforms per frame of scrolling (row and line) plus a data attribute toggled on six dots; nothing is laid out again. | Chrome, Edge and Safari 26+; script fallback elsewhere |
| Pinned Book List Row with Giant Word Parallax | CSS and a small script | 3.9 KB | Two layers each move with one translateX per scroll frame; the covers are CSS shapes with no image downloads. | Chrome, Edge and Safari 26+; script fallback elsewhere |
| Pinned Hedge Planting Steps with Dot Navigation | CSS and a small script | 4.1 KB | One translateX per scroll frame on the panel row, plus an aria-current swap on five buttons; the photos load once at a fixed ratio. | Chrome, Edge and Safari 26+; script fallback elsewhere |
| Pinned Pottery Gallery Row Sliding Sideways | CSS and a small script | 4 KB | One translateX on a single row, driven by a view timeline where supported or one rAF-throttled write per scroll elsewhere. | Chrome, Edge and Safari 26+; script fallback elsewhere |
| Snap Photo Strip with Centre Card Growing | CSS only | 3.1 KB | Each card animates only transform and an overlay's opacity on the compositor; the fallback writes them once per frame while scrolling. | Chrome, Edge and Safari 26+; script fallback elsewhere |
| Snap Scroll Bread Shelf with Arrow Buttons | CSS only | 3 KB | Scrolling and snapping are native; the script only flips two attributes and one scaleX on the progress bar per scroll event. | All current browsers |
Drag to Scroll Weekly Timetable Row with Snap
A climbing centre's week laid out as seven day cards in a sideways row. Mouse users can grab the row and drag it, touch users swipe, and keyboard users scroll it or use the arrow buttons; each way settles with a day card snapped to the left edge. Snap is paused during a drag so the row follows the hand without fighting it.
<section class="w5drg-root" data-w5drg aria-labelledby="w5drg-title">
<div class="w5drg-head">
<div>
<p class="w5drg-label">Northwall Climbing</p>
<h2 class="w5drg-title" id="w5drg-title">This week on the wall</h2>
<p class="w5drg-lede">Drag, swipe or use the arrows to see every day.</p>
</div>
<div class="w5drg-btns">
<button type="button" class="w5drg-prev" aria-controls="w5drg-row" aria-label="Earlier days"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M12.5 4.5 7 10l5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="w5drg-next" aria-controls="w5drg-row" aria-label="Later days"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M7.5 4.5 13 10l-5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
</div>
</div>
<ul class="w5drg-row" id="w5drg-row" role="list" tabindex="0" aria-label="Timetable by day, scroll sideways">
<li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Monday</h3><span class="w5drg-note">Late opening</span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">7:00</span><span class="w5drg-c">Early bouldering</span><span class="w5drg-lv w5drg-a">All levels</span></li><li class="w5drg-s"><span class="w5drg-t">12:30</span><span class="w5drg-c">Lunch hour circuits</span><span class="w5drg-lv w5drg-i">Improver</span></li><li class="w5drg-s"><span class="w5drg-t">18:00</span><span class="w5drg-c">First time on the wall</span><span class="w5drg-lv w5drg-b">Beginner</span></li><li class="w5drg-s"><span class="w5drg-t">20:00</span><span class="w5drg-c">Lead skills</span><span class="w5drg-lv w5drg-i">Improver</span></li>
</ul>
</li><li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Tuesday</h3><span class="w5drg-note"></span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">10:00</span><span class="w5drg-c">Parent and toddler</span><span class="w5drg-lv w5drg-a">All levels</span></li><li class="w5drg-s"><span class="w5drg-t">17:30</span><span class="w5drg-c">Youth squad</span><span class="w5drg-lv w5drg-i">Improver</span></li><li class="w5drg-s"><span class="w5drg-t">19:30</span><span class="w5drg-c">Technique clinic</span><span class="w5drg-lv w5drg-i">Improver</span></li>
</ul>
</li><li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Wednesday</h3><span class="w5drg-note">Women's night</span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">7:00</span><span class="w5drg-c">Early bouldering</span><span class="w5drg-lv w5drg-a">All levels</span></li><li class="w5drg-s"><span class="w5drg-t">18:00</span><span class="w5drg-c">First time on the wall</span><span class="w5drg-lv w5drg-b">Beginner</span></li><li class="w5drg-s"><span class="w5drg-t">19:30</span><span class="w5drg-c">Women's social climb</span><span class="w5drg-lv w5drg-a">All levels</span></li>
</ul>
</li><li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Thursday</h3><span class="w5drg-note"></span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">12:30</span><span class="w5drg-c">Lunch hour circuits</span><span class="w5drg-lv w5drg-i">Improver</span></li><li class="w5drg-s"><span class="w5drg-t">18:00</span><span class="w5drg-c">Belay course, part one</span><span class="w5drg-lv w5drg-b">Beginner</span></li><li class="w5drg-s"><span class="w5drg-t">20:00</span><span class="w5drg-c">Strength and fingers</span><span class="w5drg-lv w5drg-i">Improver</span></li>
</ul>
</li><li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Friday</h3><span class="w5drg-note">Open until 11</span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">17:00</span><span class="w5drg-c">After school club</span><span class="w5drg-lv w5drg-b">Beginner</span></li><li class="w5drg-s"><span class="w5drg-t">19:00</span><span class="w5drg-c">Friday social</span><span class="w5drg-lv w5drg-a">All levels</span></li><li class="w5drg-s"><span class="w5drg-t">21:00</span><span class="w5drg-c">Late bouldering</span><span class="w5drg-lv w5drg-a">All levels</span></li>
</ul>
</li><li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Saturday</h3><span class="w5drg-note"></span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">9:00</span><span class="w5drg-c">Kids' taster</span><span class="w5drg-lv w5drg-b">Beginner</span></li><li class="w5drg-s"><span class="w5drg-t">11:00</span><span class="w5drg-c">Belay course, part two</span><span class="w5drg-lv w5drg-b">Beginner</span></li><li class="w5drg-s"><span class="w5drg-t">14:00</span><span class="w5drg-c">Outdoor trip briefing</span><span class="w5drg-lv w5drg-i">Improver</span></li>
</ul>
</li><li class="w5drg-day">
<div class="w5drg-dh"><h3 class="w5drg-dn">Sunday</h3><span class="w5drg-note">Closes at 6</span></div>
<ul class="w5drg-list" role="list">
<li class="w5drg-s"><span class="w5drg-t">10:00</span><span class="w5drg-c">Family climb</span><span class="w5drg-lv w5drg-a">All levels</span></li><li class="w5drg-s"><span class="w5drg-t">13:00</span><span class="w5drg-c">Route setting preview</span><span class="w5drg-lv w5drg-a">All levels</span></li><li class="w5drg-s"><span class="w5drg-t">15:00</span><span class="w5drg-c">Stretch and mobility</span><span class="w5drg-lv w5drg-a">All levels</span></li>
</ul>
</li>
</ul>
<div class="w5drg-foot">
<span>Classes are booked by the session. Drop-in climbing needs no booking.</span>
<a href="#" class="w5drg-book">Book a class</a>
</div>
</section>
<style>
/* Change these: --w5drg-stone (background), --w5drg-signal (accent), --w5drg-col (day column width),
and DRAG in the script (pixels the mouse must move before a press counts as a drag). */
.w5drg-root { --w5drg-stone: #e6eaed; --w5drg-signal: #c2410c; --w5drg-col: 250px; --w5drg-pad: max(20px, calc((100% - 1160px) / 2)); padding: 52px 0 44px; background: var(--w5drg-stone); color: #15202b; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
.w5drg-root *, .w5drg-root *::before { box-sizing: border-box; }
.w5drg-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 0 var(--w5drg-pad); }
.w5drg-label { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: #9a3412; }
.w5drg-label::before { content: ""; width: 18px; height: 3px; background: var(--w5drg-signal); }
.w5drg-title { margin: 8px 0 0; font-size: clamp(28px, 4vw, 40px); font-weight: 750; letter-spacing: -.025em; line-height: 1.05; }
.w5drg-lede { margin: 8px 0 0; font-size: 15px; color: #3d4a57; }
.w5drg-btns { display: flex; gap: 8px; }
.w5drg-btns button { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border: 0; border-radius: 8px; background: #15202b; color: #fff; cursor: pointer; transition: background-color .2s ease, transform .15s ease; }
.w5drg-btns button:hover { background: #2a3846; }
.w5drg-btns button:active { transform: scale(.94); }
.w5drg-btns button[aria-disabled="true"] { background: #b8c1c9; color: #3d4a57; cursor: default; }
.w5drg-btns button:focus-visible, .w5drg-row:focus-visible, .w5drg-book:focus-visible { outline: 3px solid var(--w5drg-signal); outline-offset: 3px; }
.w5drg-row { display: flex; gap: 14px; margin: 26px 0 0; padding: 4px var(--w5drg-pad) 10px; list-style: none; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: var(--w5drg-pad); scrollbar-width: none; overscroll-behavior-x: contain; }
.w5drg-row::-webkit-scrollbar { display: none; }
.w5drg-root[data-drag] .w5drg-row { scroll-snap-type: none; cursor: grabbing; user-select: none; }
@media (hover: hover) and (pointer: fine) { .w5drg-row { cursor: grab; } }
.w5drg-day { flex: 0 0 var(--w5drg-col); scroll-snap-align: start; padding: 18px 18px 8px; border-radius: 12px; background: #fff; box-shadow: 0 1px 0 rgba(21, 32, 43, .06), 0 14px 30px -24px rgba(21, 32, 43, .5); }
.w5drg-dh { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 0 6px; }
.w5drg-dn { margin: 0; font-size: 18px; font-weight: 700; }
.w5drg-note { font-size: 12px; font-weight: 600; color: #9a3412; }
.w5drg-list { margin: 0; padding: 0; list-style: none; }
.w5drg-s { display: grid; grid-template-columns: 52px 1fr; gap: 2px 10px; padding: 12px 0; border-top: 1px solid #e3e7eb; }
.w5drg-t { grid-row: span 2; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.w5drg-c { font-size: 15px; line-height: 1.35; }
.w5drg-lv { justify-self: start; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.w5drg-b { background: #e3efe6; color: #1d5130; }
.w5drg-i { background: #fde7d9; color: #8a2c0a; }
.w5drg-a { background: #e5e9f2; color: #2f3c5c; }
.w5drg-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin: 22px var(--w5drg-pad) 0; font-size: 14px; color: #3d4a57; }
.w5drg-book { display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border-radius: 8px; background: var(--w5drg-signal); color: #fff; font-weight: 600; text-decoration: none; }
.w5drg-book:hover { background: #9a3412; }
@media (max-width: 639px) { .w5drg-head { flex-direction: column; align-items: flex-start; } .w5drg-root { --w5drg-col: 236px; } }
@media (prefers-reduced-motion: reduce) { .w5drg-btns button { transition: none; } }
</style>
<script>
(function () {
var root = document.querySelector("[data-w5drg]");
if (!root) return;
var $ = function (s) { return root.querySelector(s); };
var row = $(".w5drg-row"), prev = $(".w5drg-prev"), next = $(".w5drg-next");
var rm = matchMedia("(prefers-reduced-motion: reduce)");
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var go = function (d) { row.scrollBy({ left: d * row.clientWidth * 0.8, behavior: rm.matches ? "auto" : "smooth" }); };
var DRAG = 6; // pixels a mouse press must travel before it becomes a drag
var drag = null, moved = false;
row.addEventListener("pointerdown", function (e) {
if (e.pointerType !== "mouse" || e.button) return;
drag = { x: e.clientX, s: row.scrollLeft, id: e.pointerId };
moved = false;
}, o);
row.addEventListener("pointermove", function (e) {
if (!drag) return;
var dx = e.clientX - drag.x;
if (!moved && Math.abs(dx) > DRAG) { moved = true; root.setAttribute("data-drag", ""); row.setPointerCapture(drag.id); }
if (moved) row.scrollLeft = drag.s - dx;
}, o);
function end() { drag = null; root.removeAttribute("data-drag"); }
row.addEventListener("pointerup", end, o);
row.addEventListener("pointercancel", end, o);
// A drag that ends on a link should not follow it.
row.addEventListener("click", function (e) { if (moved) { e.preventDefault(); moved = false; } }, { capture: true, signal: ac.signal });
function paint() {
var max = row.scrollWidth - row.clientWidth, x = row.scrollLeft;
prev.setAttribute("aria-disabled", String(x < 4));
next.setAttribute("aria-disabled", String(x > max - 4));
}
prev.addEventListener("click", function () { go(-1); }, o);
next.addEventListener("click", function () { go(1); }, o);
row.addEventListener("scroll", paint, o);
window.addEventListener("resize", paint, o);
paint();
return function () {
ac.abort();
};
})();
</script>
With reduced motion: The arrow buttons jump a day at a time with no glide; dragging still works because it follows the hand directly.
Running cost: Drag writes scrollLeft only while a mouse button is held; otherwise the row is native scrolling with snap.
- Change `--w5drg-col` for the day column width and `--w5drg-signal` for the accent on labels and the booking button.
- Raise `DRAG` in the script if clicks on links inside the row get mistaken for drags.
- Edit days, times and levels in the `days` array; levels map to the `b`, `i` and `a` chip colours.
Full Width Snap Slides with Project Name Tabs
An architecture practice shows one project at a time: each slide fills the width with a photo and a short write-up, and the row stops on every slide rather than skipping past. Project names above act as a jump list, with an underline that follows whichever slide is in view, plus a counter and arrows for stepping through.
<section class="w5prj-root" data-w5prj aria-labelledby="w5prj-title">
<div class="w5prj-head">
<div>
<p class="w5prj-label">Arden & Vale Architects</p>
<h2 class="w5prj-title" id="w5prj-title">Selected projects</h2>
</div>
<div class="w5prj-btns">
<span class="w5prj-count" aria-hidden="true">1 / 4</span>
<button type="button" class="w5prj-prev" aria-controls="w5prj-row" aria-label="Previous project"><svg width="18" height="18" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M12.5 4.5 7 10l5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="w5prj-next" aria-controls="w5prj-row" aria-label="Next project"><svg width="18" height="18" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M7.5 4.5 13 10l-5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
</div>
</div>
<nav class="w5prj-tabs" aria-label="Projects">
<button type="button" class="w5prj-tab" aria-controls="w5prj-row">Hollow Lane House</button><button type="button" class="w5prj-tab" aria-controls="w5prj-row">Quarry Street</button><button type="button" class="w5prj-tab" aria-controls="w5prj-row">Westbrook Library</button><button type="button" class="w5prj-tab" aria-controls="w5prj-row">Palm Court</button>
</nav>
<ul class="w5prj-row" id="w5prj-row" role="list" tabindex="0" aria-label="Projects, scroll sideways">
<li class="w5prj-slide">
<div class="w5prj-photo"><img src="https://images.pexels.com/photos/13041129/pexels-photo-13041129.jpeg?auto=compress&cs=tinysrgb&w=1200" alt="A low concrete house with tall glass doors opening onto a stone path and a lawn" width="1200" height="900" loading="eager" /></div>
<div class="w5prj-copy">
<p class="w5prj-k">Project 1 of 4</p>
<h3 class="w5prj-name">Hollow Lane House</h3>
<p class="w5prj-kind">New home in a walled garden</p>
<p class="w5prj-text">A single storey house set low behind an old brick wall, so the garden reads first and the building second. Every room opens onto grass.</p>
<a href="#" class="w5prj-link">Read about Hollow Lane House</a>
</div>
</li><li class="w5prj-slide">
<div class="w5prj-photo"><img src="https://images.pexels.com/photos/12713154/pexels-photo-12713154.jpeg?auto=compress&cs=tinysrgb&w=1200" alt="A grey concrete house built from stacked box shapes with planting along its front and an open garage" width="1200" height="900" loading="eager" /></div>
<div class="w5prj-copy">
<p class="w5prj-k">Project 2 of 4</p>
<h3 class="w5prj-name">Quarry Street</h3>
<p class="w5prj-kind">Two homes on a narrow plot</p>
<p class="w5prj-text">Two family houses stacked like blocks on a gap site, with roof terraces where the street could not give them gardens.</p>
<a href="#" class="w5prj-link">Read about Quarry Street</a>
</div>
</li><li class="w5prj-slide">
<div class="w5prj-photo"><img src="https://images.pexels.com/photos/31390421/pexels-photo-31390421.jpeg?auto=compress&cs=tinysrgb&w=1200" alt="A library hall with curved tiers of seating below tall wooden bookshelves" width="1200" height="900" loading="eager" /></div>
<div class="w5prj-copy">
<p class="w5prj-k">Project 3 of 4</p>
<h3 class="w5prj-name">Westbrook Library</h3>
<p class="w5prj-kind">Public library refit</p>
<p class="w5prj-text">We took out a suspended ceiling, found the original timber roof and wrapped the reading room in shelves and stepped seats.</p>
<a href="#" class="w5prj-link">Read about Westbrook Library</a>
</div>
</li><li class="w5prj-slide">
<div class="w5prj-photo"><img src="https://images.pexels.com/photos/15391694/pexels-photo-15391694.jpeg?auto=compress&cs=tinysrgb&w=1200" alt="A two storey concrete villa with dark window frames half hidden by palm trees" width="1200" height="900" loading="eager" /></div>
<div class="w5prj-copy">
<p class="w5prj-k">Project 4 of 4</p>
<h3 class="w5prj-name">Palm Court</h3>
<p class="w5prj-kind">Holiday house in a warm climate</p>
<p class="w5prj-text">Thick walls and deep window reveals keep the rooms cool without much help, and the planting is left to grow up the facade.</p>
<a href="#" class="w5prj-link">Read about Palm Court</a>
</div>
</li>
</ul>
</section>
<style>
/* Change these: --w5prj-ink (text and active tab), --w5prj-line (rules), --w5prj-max (content width),
and the photo ratio in .w5prj-photo (aspect-ratio). */
.w5prj-root { --w5prj-ink: #1e293b; --w5prj-line: #d5dbe3; --w5prj-max: 1160px; --w5prj-pad: max(20px, calc((100% - var(--w5prj-max)) / 2)); padding: 52px 0 44px; background: #ffffff; color: var(--w5prj-ink); font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
.w5prj-root *, .w5prj-root *::before { box-sizing: border-box; }
.w5prj-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 0 var(--w5prj-pad); }
.w5prj-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: #475569; }
.w5prj-title { margin: 8px 0 0; font-size: clamp(28px, 4vw, 40px); font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.w5prj-btns { display: flex; align-items: center; gap: 8px; }
.w5prj-count { margin-right: 8px; font-size: 14px; font-variant-numeric: tabular-nums; color: #475569; }
.w5prj-btns button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--w5prj-line); border-radius: 10px; background: #fff; color: var(--w5prj-ink); cursor: pointer; transition: background-color .2s ease, border-color .2s ease; }
.w5prj-btns button:hover { background: #f1f5f9; border-color: #94a3b8; }
.w5prj-btns button[aria-disabled="true"] { opacity: .4; cursor: default; }
.w5prj-tabs { display: flex; gap: 4px 28px; flex-wrap: wrap; margin: 24px var(--w5prj-pad) 0; border-bottom: 1px solid var(--w5prj-line); }
.w5prj-tab { position: relative; min-height: 44px; padding: 0; border: 0; background: none; color: #475569; font: inherit; font-size: 15px; cursor: pointer; }
.w5prj-tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--w5prj-ink); transform: scaleX(0); transform-origin: 0 50%; transition: transform .4s cubic-bezier(.2, .7, .2, 1); }
.w5prj-tab:hover { color: var(--w5prj-ink); }
.w5prj-tab[aria-current="true"] { color: var(--w5prj-ink); font-weight: 600; }
.w5prj-tab[aria-current="true"]::after { transform: scaleX(1); }
.w5prj-btns button:focus-visible, .w5prj-tab:focus-visible, .w5prj-row:focus-visible, .w5prj-link:focus-visible { outline: 3px solid #334155; outline-offset: 3px; border-radius: 6px; }
.w5prj-row { display: flex; margin: 28px 0 0; padding: 0; list-style: none; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.w5prj-row::-webkit-scrollbar { display: none; }
.w5prj-slide { flex: 0 0 100%; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: center; padding: 0 var(--w5prj-pad); scroll-snap-align: start; scroll-snap-stop: always; }
.w5prj-photo { aspect-ratio: 16 / 10; overflow: hidden; border-radius: 4px; background: #e2e8f0; }
.w5prj-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.w5prj-k { margin: 0; font-size: 13px; color: #475569; font-variant-numeric: tabular-nums; }
.w5prj-name { margin: 10px 0 0; font-size: clamp(24px, 3vw, 32px); font-weight: 600; letter-spacing: -.015em; line-height: 1.15; }
.w5prj-kind { margin: 6px 0 0; font-size: 15px; color: #475569; }
.w5prj-text { margin: 18px 0 0; max-width: 44ch; font-size: 16px; line-height: 1.65; color: #334155; }
.w5prj-link { display: inline-flex; align-items: center; min-height: 44px; margin-top: 12px; color: var(--w5prj-ink); font-size: 15px; font-weight: 600; text-decoration: underline; text-underline-offset: 5px; }
@media (max-width: 767px) {
.w5prj-slide { grid-template-columns: 1fr; align-items: start; gap: 18px; }
.w5prj-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 22px; }
.w5prj-tab { flex: 0 0 auto; }
.w5prj-count { display: none; }
}
@media (prefers-reduced-motion: reduce) { .w5prj-tab::after, .w5prj-btns button { transition: none; } }
</style>
<script>
(function () {
var root = document.querySelector("[data-w5prj]");
if (!root) return;
var $ = function (s) { return root.querySelector(s); };
var row = $(".w5prj-row"), prev = $(".w5prj-prev"), next = $(".w5prj-next");
var rm = matchMedia("(prefers-reduced-motion: reduce)");
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var go = function (d) { row.scrollBy({ left: d * row.clientWidth * 0.8, behavior: rm.matches ? "auto" : "smooth" }); };
var tabs = root.querySelectorAll(".w5prj-tab"), count = $(".w5prj-count"), cur = -1;
tabs.forEach(function (t, i) {
t.addEventListener("click", function () { row.scrollTo({ left: i * row.clientWidth, behavior: rm.matches ? "auto" : "smooth" }); }, o);
});
go = function (d) { row.scrollBy({ left: d * row.clientWidth, behavior: rm.matches ? "auto" : "smooth" }); };
function paint() {
var max = row.scrollWidth - row.clientWidth, x = row.scrollLeft;
prev.setAttribute("aria-disabled", String(x < 4));
next.setAttribute("aria-disabled", String(x > max - 4));
var a = Math.round(x / row.clientWidth);
if (a === cur) return;
cur = a;
count.textContent = a + 1 + " / " + tabs.length;
tabs.forEach(function (t, i) { t.setAttribute("aria-current", String(i === a)); });
}
prev.addEventListener("click", function () { go(-1); }, o);
next.addEventListener("click", function () { go(1); }, o);
row.addEventListener("scroll", paint, o);
window.addEventListener("resize", paint, o);
paint();
return function () {
ac.abort();
};
})();
</script>
With reduced motion: The names and arrows move to a slide in one jump with no glide, and the underline swaps without sliding.
Running cost: Native snap scrolling with one scroll listener that only touches the DOM when the slide in view changes.
- Change the photo shape with `aspect-ratio` on `.w5prj-photo`, and the split with the `grid-template-columns` of `.w5prj-slide`.
- Set `--w5prj-max` to your container width and `--w5prj-ink` for text, the active name and its underline.
- Edit names, summaries and photos in the `projects` array; the names row and counter are built from it.
Pinned Boat Restoration Timeline Drawing Sideways
A boatyard explains its six restoration stages on a timeline that pins and travels left as you scroll down. A brass line draws itself along the row, and each stage's dot fills the moment the line reaches it, with cards alternating above and below. Good for any ordered process where the sense of moving forward matters.
<section class="w5tml-root" data-w5tml tabindex="0" aria-label="Restoration timeline, scroll to move along it">
<div class="w5tml-track">
<div class="w5tml-stage">
<div class="w5tml-hint" aria-hidden="true"><span>Scroll inside</span></div>
<div class="w5tml-head">
<p class="w5tml-label">Merrow Boatworks</p>
<h2 class="w5tml-title">How we bring a wooden dayboat back</h2>
</div>
<div class="w5tml-row">
<span class="w5tml-line" aria-hidden="true"><span class="w5tml-ink"></span></span>
<ol class="w5tml-list">
<li class="w5tml-panel w5tml-up">
<span class="w5tml-dot" aria-hidden="true"></span>
<div class="w5tml-card">
<p class="w5tml-n">Stage 1</p>
<h3 class="w5tml-h">Survey on the hard</h3>
<p class="w5tml-text">We lift her out, sound every plank with a mallet and mark the soft wood in chalk.</p>
</div>
</li><li class="w5tml-panel w5tml-down">
<span class="w5tml-dot" aria-hidden="true"></span>
<div class="w5tml-card">
<p class="w5tml-n">Stage 2</p>
<h3 class="w5tml-h">Strip back to bare cedar</h3>
<p class="w5tml-text">Old paint comes off by scraper and low heat, so the timber is never scorched.</p>
</div>
</li><li class="w5tml-panel w5tml-up">
<span class="w5tml-dot" aria-hidden="true"></span>
<div class="w5tml-card">
<p class="w5tml-n">Stage 3</p>
<h3 class="w5tml-h">Steam new oak frames</h3>
<p class="w5tml-text">Cracked frames are steamed soft, bent to the curve of the hull and riveted in copper.</p>
</div>
</li><li class="w5tml-panel w5tml-down">
<span class="w5tml-dot" aria-hidden="true"></span>
<div class="w5tml-card">
<p class="w5tml-n">Stage 4</p>
<h3 class="w5tml-h">Plank lap over lap</h3>
<p class="w5tml-text">New larch planks are cut from patterns of the old ones and fastened one over the next.</p>
</div>
</li><li class="w5tml-panel w5tml-up">
<span class="w5tml-dot" aria-hidden="true"></span>
<div class="w5tml-card">
<p class="w5tml-n">Stage 5</p>
<h3 class="w5tml-h">Fair, prime and paint</h3>
<p class="w5tml-text">Coat after coat above the waterline, sanded between each, with antifouling below.</p>
</div>
</li><li class="w5tml-panel w5tml-down">
<span class="w5tml-dot" aria-hidden="true"></span>
<div class="w5tml-card">
<p class="w5tml-n">Stage 6</p>
<h3 class="w5tml-h">Back in on a spring tide</h3>
<p class="w5tml-text">She takes up water for a day or two at the mooring, then sails the following week.</p>
</div>
</li>
<li class="w5tml-panel w5tml-end">
<div class="w5tml-card w5tml-cta">
<h3 class="w5tml-h">Have a boat that needs this?</h3>
<a href="#" class="w5tml-btn">Book a hull survey</a>
</div>
</li>
</ol>
</div>
</div>
</div>
</section>
<style>
/* Change these: --w5tml-navy (background), --w5tml-brass (line and dots), --w5tml-col (width of each stage),
--w5tml-run (scroll distance for the whole timeline), and AUTO in the script (demo speed, 0 turns it off). */
.w5tml-root { --w5tml-h: 600px; --w5tml-run: 1600px; position: relative; height: var(--w5tml-h); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
.w5tml-root *, .w5tml-root *::before, .w5tml-root *::after { box-sizing: border-box; }
.w5tml-track { height: calc(var(--w5tml-h) + var(--w5tml-run)); }
.w5tml-stage { position: sticky; top: 0; height: var(--w5tml-h); overflow: hidden; container-type: inline-size; }
.w5tml-row { position: relative; display: flex; width: max-content; will-change: transform; }
.w5tml-hint { position: absolute; top: 12px; left: 0; right: 0; z-index: 5; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }
.w5tml-hint span { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.w5tml-root[data-scrolled] .w5tml-hint { opacity: 0; }
@keyframes w5tml-slide { to { transform: translateX(calc(-100% + 100cqi)); } }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5tml-track { view-timeline: --w5tml-tl block; }
.w5tml-row { animation: w5tml-slide linear both; animation-timeline: --w5tml-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5tml-track { height: auto; }
.w5tml-stage { position: static; height: auto; min-height: var(--w5tml-h); overflow: visible; }
.w5tml-hint { display: none; }
.w5tml-row { width: auto; overflow-x: auto; scroll-snap-type: x mandatory; transform: none !important; animation: none !important; scrollbar-width: thin; scroll-padding-inline: clamp(20px, 5cqi, 64px); }
.w5tml-panel { scroll-snap-align: start; }
}
.w5tml-root { --w5tml-navy: #0e1d30; --w5tml-brass: #d9b56c; --w5tml-col: 300px; background: radial-gradient(120% 90% at 20% 0%, #183150 0%, var(--w5tml-navy) 60%); color: #efe9dd; font-family: ui-sans-serif, system-ui, sans-serif; scrollbar-color: #2e4868 transparent; }
.w5tml-root:focus-visible { outline: 3px solid var(--w5tml-brass); outline-offset: -3px; }
.w5tml-hint span { background: var(--w5tml-brass); color: var(--w5tml-navy); }
.w5tml-stage { display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.w5tml-head { padding: 0 clamp(20px, 5cqi, 64px); }
.w5tml-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--w5tml-brass); }
.w5tml-title { margin: 8px 0 0; max-width: 18ch; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(28px, 3.8cqi, 42px); line-height: 1.12; }
.w5tml-row { padding: 0 clamp(20px, 5cqi, 64px); }
.w5tml-list { display: flex; margin: 0; padding: 0; list-style: none; }
.w5tml-panel { position: relative; flex: 0 0 var(--w5tml-col); height: 400px; }
.w5tml-line { position: absolute; top: 200px; left: calc(clamp(20px, 5cqi, 64px) + 25px); right: calc(clamp(20px, 5cqi, 64px) + 280px + var(--w5tml-col) - 25px); height: 2px; background: rgba(239, 233, 221, .16); }
.w5tml-ink { position: absolute; inset: 0; background: var(--w5tml-brass); transform: scaleX(0); transform-origin: 0 50%; }
.w5tml-dot { position: absolute; top: 193px; left: 17px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--w5tml-brass); background: var(--w5tml-navy); }
.w5tml-dot::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--w5tml-brass); opacity: 0; transform: scale(.4); transition: opacity .35s ease, transform .35s cubic-bezier(.3, 1.6, .5, 1); }
.w5tml-panel[data-on] .w5tml-dot::after { opacity: 1; transform: scale(1); }
.w5tml-card { position: absolute; left: 0; width: calc(var(--w5tml-col) - 36px); padding: 0 0 0 24px; border-left: 1px solid rgba(217, 181, 108, .45); }
.w5tml-up .w5tml-card { bottom: 228px; }
.w5tml-down .w5tml-card { top: 228px; }
.w5tml-n { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--w5tml-brass); }
.w5tml-h { margin: 6px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: 22px; line-height: 1.25; }
.w5tml-text { margin: 8px 0 0; font-size: 15px; line-height: 1.6; color: #c9c3b8; }
.w5tml-end { flex-basis: 280px; }
.w5tml-cta { top: 150px; border-left: 0; padding: 0; }
.w5tml-btn { display: inline-flex; align-items: center; min-height: 44px; margin-top: 16px; padding: 0 20px; border-radius: 999px; background: var(--w5tml-brass); color: var(--w5tml-navy); font-size: 14px; font-weight: 600; text-decoration: none; }
.w5tml-btn:hover { background: #ecd29a; }
.w5tml-btn:focus-visible { outline: 3px solid #efe9dd; outline-offset: 3px; }
@keyframes w5tml-draw { to { transform: scaleX(1); } }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5tml-ink { animation: w5tml-draw linear both; animation-timeline: --w5tml-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5tml-stage { justify-content: center; gap: 24px; padding: 32px 0; }
.w5tml-row { padding: 0; }
.w5tml-list { gap: 16px; padding: 0 20px 12px; }
.w5tml-line, .w5tml-dot { display: none; }
.w5tml-panel, .w5tml-end { flex: 0 0 min(80%, 300px); height: auto; scroll-snap-align: start; }
.w5tml-card, .w5tml-cta { position: static; width: auto; height: 100%; padding: 20px; border: 1px solid rgba(217, 181, 108, .4); border-radius: 14px; background: rgba(255, 255, 255, .04); }
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5tml-row { overflow: visible; }
.w5tml-list { overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 20px; scrollbar-width: thin; }
}
</style>
<script>
(function () {
var root = document.querySelector("[data-w5tml]");
if (!root) return;
// The box scrolls itself. For page scroll: remove height and overflow from .w5tml-root, set --w5tml-h to 100vh,
// then use window scroll events and (scrollY minus the track's page top) instead of root.scrollTop.
var AUTO = 80; // demo scroll speed in px per second until someone scrolls; 0 turns it off
var $ = function (s) { return root.querySelector(s); };
var track = $(".w5tml-track"), stage = $(".w5tml-stage"), row = $(".w5tml-row");
var still = matchMedia("(prefers-reduced-motion: reduce), (max-width: 639px)");
var css = window.CSS && CSS.supports("animation-timeline: view()"); // CSS moves the row itself there
var af = requestAnimationFrame, caf = cancelAnimationFrame, raf = 0, demo = 0, last = 0, pos = 0, seen = true, done = !AUTO;
var ink = $(".w5tml-ink"), dots = root.querySelectorAll(".w5tml-dot"), n = dots.length;
function cl(x) { return Math.min(1, Math.max(0, x)) || 0; }
function span() { return track.offsetHeight - root.clientHeight; }
function shift(el, p, flat) {
if (!css) el.style.transform = flat ? "" : "translateX(" + -p * Math.max(0, el.offsetWidth - stage.clientWidth) + "px)";
}
function paint() {
raf = 0;
var p = cl((root.scrollTop - track.offsetTop) / span()), flat = still.matches;
root.toggleAttribute("data-scrolled", root.scrollTop > 160);
shift(row, p, flat);
if (!css) ink.style.transform = flat ? "" : "scaleX(" + p + ")";
dots.forEach(function (d, i) { d.parentNode.toggleAttribute("data-on", flat || p >= i / (n - 1) - 0.02); });
}
function queue() { if (!raf) raf = af(paint); }
function step(now) {
var dt = last ? Math.min(now - last, 50) : 0;
last = now;
pos += (AUTO * dt) / 1000;
if (pos >= root.scrollHeight - root.clientHeight) { done = true; demo = 0; return; }
root.scrollTop = pos;
demo = af(step);
}
function start() { if (!done && seen && !demo && !still.matches) { last = 0; pos = root.scrollTop; demo = af(step); } }
function stop() { caf(demo); demo = 0; }
function hand() { done = true; stop(); }
// Tabbing to a card off to the side scrolls the box to the point where that card is in view.
function focusIn(e) {
var card = e.target.closest(".w5tml-panel");
stage.scrollLeft = 0;
if (!card || still.matches) return;
hand();
var w = stage.clientWidth;
root.scrollTop = track.offsetTop + span() * cl((card.offsetLeft - (w - card.offsetWidth) / 2) / (row.offsetWidth - w));
}
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; seen ? start() : stop(); });
io.observe(root);
["wheel", "touchstart", "pointerdown", "keydown"].forEach(function (ev) { root.addEventListener(ev, hand, o); });
root.addEventListener("scroll", queue, o);
row.addEventListener("focusin", focusIn, o);
row.addEventListener("scroll", queue, o);
window.addEventListener("resize", queue, o);
paint();
start();
return function () {
stop();
caf(raf);
io.disconnect();
ac.abort();
};
})();
</script>
With reduced motion: The timeline becomes a row of bordered stage cards to swipe through, with no pinning, no drawn line and every stage shown at once.
Running cost: Two transforms per frame of scrolling (row and line) plus a data attribute toggled on six dots; nothing is laid out again.
- Change `--w5tml-col` to widen or narrow every stage column; the line and dots follow.
- Use `--w5tml-brass` for the line, dots and labels, and `--w5tml-navy` for the background.
- Edit the `stages` array; set `side` to `up` or `down` to choose where each card sits.
Pinned Book List Row with Giant Word Parallax
A small publisher's season of new titles on a dark pinned stage. Scrolling down moves the row of drawn book covers sideways while an outlined italic phrase behind them drifts at a slower pace, because both layers cross the same scroll range but the phrase is shorter. That gap in speed gives depth with no extra maths.
<section class="w5gwd-root" data-w5gwd tabindex="0" aria-label="Spring books, scroll to move sideways">
<div class="w5gwd-track">
<div class="w5gwd-stage">
<div class="w5gwd-hint" aria-hidden="true"><span>Scroll inside</span></div>
<p class="w5gwd-word" aria-hidden="true">New for spring</p>
<div class="w5gwd-head">
<p class="w5gwd-label">Oxbow Press</p>
<h2 class="w5gwd-title">Six new books for spring</h2>
</div>
<ul class="w5gwd-row" role="list">
<li class="w5gwd-panel">
<a href="#" class="w5gwd-book">
<span class="w5gwd-cover w5gwd-c1" aria-hidden="true"><span class="w5gwd-ct">The Salt Road</span><span class="w5gwd-ca">Ines Marlow</span></span>
<span class="w5gwd-bt">The Salt Road</span>
<span class="w5gwd-ba">Ines Marlow</span>
<span class="w5gwd-bk"><span>Novel, out in March</span><span>$24</span></span>
</a>
</li><li class="w5gwd-panel">
<a href="#" class="w5gwd-book">
<span class="w5gwd-cover w5gwd-c2" aria-hidden="true"><span class="w5gwd-ct">Small Hours</span><span class="w5gwd-ca">Theo Garrick</span></span>
<span class="w5gwd-bt">Small Hours</span>
<span class="w5gwd-ba">Theo Garrick</span>
<span class="w5gwd-bk"><span>Poems, out in March</span><span>$18</span></span>
</a>
</li><li class="w5gwd-panel">
<a href="#" class="w5gwd-book">
<span class="w5gwd-cover w5gwd-c3" aria-hidden="true"><span class="w5gwd-ct">A Field Guide to Fog</span><span class="w5gwd-ca">Rhona Pell</span></span>
<span class="w5gwd-bt">A Field Guide to Fog</span>
<span class="w5gwd-ba">Rhona Pell</span>
<span class="w5gwd-bk"><span>Essays, out in April</span><span>$22</span></span>
</a>
</li><li class="w5gwd-panel">
<a href="#" class="w5gwd-book">
<span class="w5gwd-cover w5gwd-c4" aria-hidden="true"><span class="w5gwd-ct">Under the Viaduct</span><span class="w5gwd-ca">Sami Okoro</span></span>
<span class="w5gwd-bt">Under the Viaduct</span>
<span class="w5gwd-ba">Sami Okoro</span>
<span class="w5gwd-bk"><span>Stories, out in April</span><span>$20</span></span>
</a>
</li><li class="w5gwd-panel">
<a href="#" class="w5gwd-book">
<span class="w5gwd-cover w5gwd-c5" aria-hidden="true"><span class="w5gwd-ct">Tending</span><span class="w5gwd-ca">Mae Lindqvist</span></span>
<span class="w5gwd-bt">Tending</span>
<span class="w5gwd-ba">Mae Lindqvist</span>
<span class="w5gwd-bk"><span>Memoir, out in May</span><span>$26</span></span>
</a>
</li><li class="w5gwd-panel">
<a href="#" class="w5gwd-book">
<span class="w5gwd-cover w5gwd-c6" aria-hidden="true"><span class="w5gwd-ct">The Ninth Lock</span><span class="w5gwd-ca">Dara Finch</span></span>
<span class="w5gwd-bt">The Ninth Lock</span>
<span class="w5gwd-ba">Dara Finch</span>
<span class="w5gwd-bk"><span>Crime, out in May</span><span>$19</span></span>
</a>
</li>
<li class="w5gwd-panel w5gwd-end">
<p class="w5gwd-endtext">Order any two before publication and we post them together, signed where we can.</p>
<a href="#" class="w5gwd-btn">See the full catalogue</a>
</li>
</ul>
</div>
</div>
</section>
<style>
/* Change these: --w5gwd-ink (background), --w5gwd-amber (accent), --w5gwd-run (scroll distance),
the .w5gwd-word font-size (how big the back word is; a wider word moves faster), and AUTO in the script. */
.w5gwd-root { --w5gwd-h: 620px; --w5gwd-run: 1500px; position: relative; height: var(--w5gwd-h); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
.w5gwd-root *, .w5gwd-root *::before, .w5gwd-root *::after { box-sizing: border-box; }
.w5gwd-track { height: calc(var(--w5gwd-h) + var(--w5gwd-run)); }
.w5gwd-stage { position: sticky; top: 0; height: var(--w5gwd-h); overflow: hidden; container-type: inline-size; }
.w5gwd-row { position: relative; display: flex; width: max-content; will-change: transform; }
.w5gwd-hint { position: absolute; top: 12px; left: 0; right: 0; z-index: 5; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }
.w5gwd-hint span { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.w5gwd-root[data-scrolled] .w5gwd-hint { opacity: 0; }
@keyframes w5gwd-slide { to { transform: translateX(calc(-100% + 100cqi)); } }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5gwd-track { view-timeline: --w5gwd-tl block; }
.w5gwd-row { animation: w5gwd-slide linear both; animation-timeline: --w5gwd-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5gwd-track { height: auto; }
.w5gwd-stage { position: static; height: auto; min-height: var(--w5gwd-h); overflow: visible; }
.w5gwd-hint { display: none; }
.w5gwd-row { width: auto; overflow-x: auto; scroll-snap-type: x mandatory; transform: none !important; animation: none !important; scrollbar-width: thin; scroll-padding-inline: clamp(20px, 5cqi, 64px); }
.w5gwd-panel { scroll-snap-align: start; }
}
.w5gwd-root { --w5gwd-ink: #1b1c1f; --w5gwd-amber: #e3a857; background: var(--w5gwd-ink); color: #ecebe6; font-family: ui-sans-serif, system-ui, sans-serif; scrollbar-color: #3a3b40 transparent; }
.w5gwd-root:focus-visible { outline: 3px solid var(--w5gwd-amber); outline-offset: -3px; }
.w5gwd-hint span { background: var(--w5gwd-amber); color: var(--w5gwd-ink); }
.w5gwd-stage { display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 48px; }
.w5gwd-head { position: absolute; top: 44px; left: clamp(20px, 5cqi, 64px); }
.w5gwd-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--w5gwd-amber); }
.w5gwd-title { margin: 8px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(26px, 3.4cqi, 38px); line-height: 1.15; }
.w5gwd-word { position: absolute; top: 120px; left: 0; margin: 0; padding: 0 clamp(20px, 5cqi, 64px); width: max-content; white-space: nowrap; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: 210px; line-height: 1; color: transparent; -webkit-text-stroke: 1.5px rgba(236, 235, 230, .2); will-change: transform; pointer-events: none; }
.w5gwd-row { margin: 0; padding: 0 clamp(20px, 5cqi, 64px); list-style: none; gap: 36px; align-items: flex-end; }
.w5gwd-panel { flex: 0 0 auto; }
.w5gwd-panel:nth-child(even) { margin-bottom: 44px; }
.w5gwd-book { display: block; width: 210px; color: inherit; text-decoration: none; border-radius: 4px; }
.w5gwd-book:focus-visible { outline: 3px solid var(--w5gwd-amber); outline-offset: 8px; }
.w5gwd-cover { position: relative; display: flex; flex-direction: column; justify-content: space-between; height: 300px; padding: 22px 20px; overflow: hidden; border-radius: 3px 8px 8px 3px; box-shadow: inset 6px 0 0 rgba(0, 0, 0, .18), 0 24px 40px -22px rgba(0, 0, 0, .8); transition: transform .5s cubic-bezier(.2, .7, .2, 1); }
.w5gwd-cover::before { content: ""; position: absolute; }
.w5gwd-book:hover .w5gwd-cover, .w5gwd-book:focus-visible .w5gwd-cover { transform: translateY(-8px) rotate(-1deg); }
.w5gwd-ct { position: relative; font-family: Georgia, "Times New Roman", serif; font-size: 25px; line-height: 1.12; }
.w5gwd-ca { position: relative; font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
.w5gwd-c1 { background: #b4532a; color: #f7e9d7; }
.w5gwd-c1::before { width: 150px; height: 150px; right: -40px; bottom: 40px; border-radius: 50%; background: #e7b98f; opacity: .55; }
.w5gwd-c2 { background: #1f4b48; color: #e5efe8; }
.w5gwd-c2::before { inset: 110px 20px 70px; background: repeating-linear-gradient(0deg, rgba(229, 239, 232, .35) 0 1px, transparent 1px 12px); }
.w5gwd-c3 { background: #d3a648; color: #2a2010; }
.w5gwd-c3::before { left: -30px; right: -30px; top: 130px; height: 80px; background: rgba(255, 250, 235, .5); border-radius: 50%; }
.w5gwd-c4 { background: #3b4e6d; color: #eef1f6; }
.w5gwd-c4::before { left: 20px; right: 20px; bottom: 60px; height: 90px; border: 2px solid rgba(238, 241, 246, .45); border-bottom: 0; border-radius: 90px 90px 0 0; }
.w5gwd-c5 { background: #e9e2d0; color: #3a3a24; }
.w5gwd-c5::before { width: 10px; height: 120px; left: 50%; bottom: 84px; background: #6b7040; border-radius: 6px; box-shadow: -26px 30px 0 #8d915e, 26px 50px 0 #8d915e; }
.w5gwd-c6 { background: #6b2330; color: #f4e3e3; }
.w5gwd-c6::before { inset: 100px 60px 60px; border: 2px solid rgba(244, 227, 227, .5); border-radius: 4px; }
.w5gwd-bt { display: block; margin-top: 16px; font-weight: 600; font-size: 15px; }
.w5gwd-ba { display: block; margin-top: 2px; font-size: 14px; color: #b9b8b2; }
.w5gwd-bk { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: #a3a29c; }
.w5gwd-end { align-self: center; width: 250px; padding-left: 28px; border-left: 1px solid #3a3b40; }
.w5gwd-endtext { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 20px; line-height: 1.4; }
.w5gwd-btn { display: inline-flex; align-items: center; min-height: 44px; margin-top: 18px; padding: 0 20px; border-radius: 999px; background: var(--w5gwd-amber); color: var(--w5gwd-ink); font-size: 14px; font-weight: 600; text-decoration: none; }
.w5gwd-btn:hover { background: #f0c488; }
.w5gwd-btn:focus-visible { outline: 3px solid #ecebe6; outline-offset: 3px; }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5gwd-word { animation: w5gwd-slide linear both; animation-timeline: --w5gwd-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5gwd-stage { justify-content: center; gap: 28px; padding: 36px 0; }
.w5gwd-head { position: static; padding: 0 20px; }
.w5gwd-word { display: none; }
.w5gwd-row { gap: 20px; padding-bottom: 12px; align-items: flex-start; }
.w5gwd-panel:nth-child(even) { margin-bottom: 0; }
.w5gwd-book { width: 180px; }
.w5gwd-cover { height: 258px; transition: none; }
}
</style>
<script>
(function () {
var root = document.querySelector("[data-w5gwd]");
if (!root) return;
// The box scrolls itself. For page scroll: remove height and overflow from .w5gwd-root, set --w5gwd-h to 100vh,
// then use window scroll events and (scrollY minus the track's page top) instead of root.scrollTop.
var AUTO = 80; // demo scroll speed in px per second until someone scrolls; 0 turns it off
var $ = function (s) { return root.querySelector(s); };
var track = $(".w5gwd-track"), stage = $(".w5gwd-stage"), row = $(".w5gwd-row");
var still = matchMedia("(prefers-reduced-motion: reduce), (max-width: 639px)");
var css = window.CSS && CSS.supports("animation-timeline: view()"); // CSS moves the row itself there
var af = requestAnimationFrame, caf = cancelAnimationFrame, raf = 0, demo = 0, last = 0, pos = 0, seen = true, done = !AUTO;
var word = $(".w5gwd-word");
function cl(x) { return Math.min(1, Math.max(0, x)) || 0; }
function span() { return track.offsetHeight - root.clientHeight; }
function shift(el, p, flat) {
if (!css) el.style.transform = flat ? "" : "translateX(" + -p * Math.max(0, el.offsetWidth - stage.clientWidth) + "px)";
}
function paint() {
raf = 0;
var p = cl((root.scrollTop - track.offsetTop) / span()), flat = still.matches;
root.toggleAttribute("data-scrolled", root.scrollTop > 160);
shift(row, p, flat);
shift(word, p, flat);
}
function queue() { if (!raf) raf = af(paint); }
function step(now) {
var dt = last ? Math.min(now - last, 50) : 0;
last = now;
pos += (AUTO * dt) / 1000;
if (pos >= root.scrollHeight - root.clientHeight) { done = true; demo = 0; return; }
root.scrollTop = pos;
demo = af(step);
}
function start() { if (!done && seen && !demo && !still.matches) { last = 0; pos = root.scrollTop; demo = af(step); } }
function stop() { caf(demo); demo = 0; }
function hand() { done = true; stop(); }
// Tabbing to a card off to the side scrolls the box to the point where that card is in view.
function focusIn(e) {
var card = e.target.closest(".w5gwd-panel");
stage.scrollLeft = 0;
if (!card || still.matches) return;
hand();
var w = stage.clientWidth;
root.scrollTop = track.offsetTop + span() * cl((card.offsetLeft - (w - card.offsetWidth) / 2) / (row.offsetWidth - w));
}
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; seen ? start() : stop(); });
io.observe(root);
["wheel", "touchstart", "pointerdown", "keydown"].forEach(function (ev) { root.addEventListener(ev, hand, o); });
root.addEventListener("scroll", queue, o);
row.addEventListener("focusin", focusIn, o);
row.addEventListener("scroll", queue, o);
window.addEventListener("resize", queue, o);
paint();
start();
return function () {
stop();
caf(raf);
io.disconnect();
ac.abort();
};
})();
</script>
With reduced motion: The background phrase is removed and the books sit in a plain sideways row that scrolls by swipe or trackpad.
Running cost: Two layers each move with one translateX per scroll frame; the covers are CSS shapes with no image downloads.
- Change the `.w5gwd-word` font-size or text: a wider phrase travels faster, a narrower one slower, against the same row.
- Recolour each cover with the `.w5gwd-c1` to `.w5gwd-c6` rules, and the page with `--w5gwd-ink` and `--w5gwd-amber`.
- Edit titles, authors and prices in the `books` array.
Pinned Hedge Planting Steps with Dot Navigation
A tree nursery's five planting steps, each a full-width panel with a photo and short instructions. Scrolling down slides one panel after another across, gentle snap points settle on each step, and a row of bar buttons shows which step is in view and jumps straight to any of them. On phones the panels become a swipeable row and the bars still work.
<section class="w5stp-root" data-w5stp tabindex="0" aria-label="Hedge planting steps, scroll to move sideways">
<div class="w5stp-track">
<span class="w5stp-snap" aria-hidden="true"></span><span class="w5stp-snap" aria-hidden="true"></span><span class="w5stp-snap" aria-hidden="true"></span><span class="w5stp-snap" aria-hidden="true"></span><span class="w5stp-snap" aria-hidden="true"></span>
<div class="w5stp-stage">
<div class="w5stp-hint" aria-hidden="true"><span>Scroll inside</span></div>
<p class="w5stp-label">Larchfield Nursery · Planting a hedge</p>
<ol class="w5stp-row">
<li class="w5stp-panel">
<div class="w5stp-photo"><img src="https://images.pexels.com/photos/32209937/pexels-photo-32209937.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Rows of young saplings growing in black bags at an outdoor nursery" width="1000" height="750" loading="eager" /></div>
<div class="w5stp-copy">
<p class="w5stp-n">Step 1 of 5</p>
<h3 class="w5stp-h">Pick plants for your soil</h3>
<p class="w5stp-text">Tell us whether your ground is heavy clay, sandy or somewhere between, and we choose hawthorn, beech or field maple to match.</p>
<p class="w5stp-tip">Bare-root plants travel from November to March.</p>
<a href="#" class="w5stp-link">Read the full guide</a>
</div>
</li><li class="w5stp-panel">
<div class="w5stp-photo"><img src="https://images.pexels.com/photos/18303688/pexels-photo-18303688.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Two hands firming dark soil around a newly planted sapling" width="1000" height="750" loading="eager" /></div>
<div class="w5stp-copy">
<p class="w5stp-n">Step 2 of 5</p>
<h3 class="w5stp-h">Plant in a double row</h3>
<p class="w5stp-text">Set them in two staggered lines a hand's width deeper than they grew, then firm the soil with your heel.</p>
<p class="w5stp-tip">Soak the roots in a bucket for an hour first.</p>
<a href="#" class="w5stp-link">Read the full guide</a>
</div>
</li><li class="w5stp-panel">
<div class="w5stp-photo"><img src="https://images.pexels.com/photos/7656746/pexels-photo-7656746.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="A metal watering can pouring water at the base of a young staked tree" width="1000" height="750" loading="eager" /></div>
<div class="w5stp-copy">
<p class="w5stp-n">Step 3 of 5</p>
<h3 class="w5stp-h">Water through the first summer</h3>
<p class="w5stp-text">A long drink once a week beats a sprinkle every evening. Roots follow the water down and hold on in dry spells.</p>
<p class="w5stp-tip">Stop once autumn rain takes over.</p>
<a href="#" class="w5stp-link">Read the full guide</a>
</div>
</li><li class="w5stp-panel">
<div class="w5stp-photo"><img src="https://images.pexels.com/photos/9890699/pexels-photo-9890699.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Close view of brown bark mulch lying in sunlight" width="1000" height="750" loading="eager" /></div>
<div class="w5stp-copy">
<p class="w5stp-n">Step 4 of 5</p>
<h3 class="w5stp-h">Mulch to keep weeds off</h3>
<p class="w5stp-text">Spread bark a few inches deep along the row, clear of the stems, so grass cannot compete for water.</p>
<p class="w5stp-tip">Top it up each spring for three years.</p>
<a href="#" class="w5stp-link">Read the full guide</a>
</div>
</li><li class="w5stp-panel">
<div class="w5stp-photo"><img src="https://images.pexels.com/photos/27397124/pexels-photo-27397124.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="A long mown garden path running between tall clipped green hedges" width="1000" height="750" loading="eager" /></div>
<div class="w5stp-copy">
<p class="w5stp-n">Step 5 of 5</p>
<h3 class="w5stp-h">Trim and let it thicken</h3>
<p class="w5stp-text">Cut back by a third after planting, then lightly each summer. The hedge fills from the base and stays dense.</p>
<p class="w5stp-tip">Ask us for a trimming reminder by email.</p>
<a href="#" class="w5stp-link">Read the full guide</a>
</div>
</li>
</ol>
<nav class="w5stp-dots" aria-label="Steps">
<button type="button" class="w5stp-dot" aria-label="Step 1: Pick plants for your soil"><span></span></button><button type="button" class="w5stp-dot" aria-label="Step 2: Plant in a double row"><span></span></button><button type="button" class="w5stp-dot" aria-label="Step 3: Water through the first summer"><span></span></button><button type="button" class="w5stp-dot" aria-label="Step 4: Mulch to keep weeds off"><span></span></button><button type="button" class="w5stp-dot" aria-label="Step 5: Trim and let it thicken"><span></span></button>
</nav>
</div>
</div>
</section>
<style>
/* Change these: --w5stp-moss (background), --w5stp-sage (accent), --w5stp-run (scroll distance for all steps; snap
points follow it). Add or remove .w5stp-snap spans with steps. */
.w5stp-root { --w5stp-h: 620px; --w5stp-run: 2000px; position: relative; height: var(--w5stp-h); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
.w5stp-root *, .w5stp-root *::before, .w5stp-root *::after { box-sizing: border-box; }
.w5stp-track { height: calc(var(--w5stp-h) + var(--w5stp-run)); }
.w5stp-stage { position: sticky; top: 0; height: var(--w5stp-h); overflow: hidden; container-type: inline-size; }
.w5stp-row { position: relative; display: flex; width: max-content; will-change: transform; }
.w5stp-hint { position: absolute; top: 12px; left: 0; right: 0; z-index: 5; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }
.w5stp-hint span { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.w5stp-root[data-scrolled] .w5stp-hint { opacity: 0; }
@keyframes w5stp-slide { to { transform: translateX(calc(-100% + 100cqi)); } }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5stp-track { view-timeline: --w5stp-tl block; }
.w5stp-row { animation: w5stp-slide linear both; animation-timeline: --w5stp-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5stp-track { height: auto; }
.w5stp-stage { position: static; height: auto; min-height: var(--w5stp-h); overflow: visible; }
.w5stp-hint { display: none; }
.w5stp-row { width: auto; overflow-x: auto; scroll-snap-type: x mandatory; transform: none !important; animation: none !important; scrollbar-width: thin; scroll-padding-inline: clamp(20px, 5cqi, 64px); }
.w5stp-panel { scroll-snap-align: start; }
}
.w5stp-root { --w5stp-moss: #1c3328; --w5stp-sage: #b7cf9f; background: var(--w5stp-moss); color: #f1eee4; font-family: ui-sans-serif, system-ui, sans-serif; scrollbar-color: #36543f transparent; }
.w5stp-root { scroll-snap-type: y proximity; }
.w5stp-root:focus-visible { outline: 3px solid var(--w5stp-sage); outline-offset: -3px; }
.w5stp-hint span { background: var(--w5stp-sage); color: var(--w5stp-moss); }
.w5stp-track { position: relative; }
.w5stp-snap { position: absolute; left: 0; width: 1px; height: 1px; scroll-snap-align: start; }
.w5stp-snap:nth-child(2) { top: calc(var(--w5stp-run) * .25); }
.w5stp-snap:nth-child(3) { top: calc(var(--w5stp-run) * .5); }
.w5stp-snap:nth-child(4) { top: calc(var(--w5stp-run) * .75); }
.w5stp-snap:nth-child(5) { top: var(--w5stp-run); }
.w5stp-stage { display: flex; flex-direction: column; justify-content: center; }
.w5stp-label { margin: 0 0 20px; padding: 0 clamp(20px, 5cqi, 64px); font-size: 12px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--w5stp-sage); }
.w5stp-row { margin: 0; padding: 0; list-style: none; }
.w5stp-panel { flex: 0 0 100cqi; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: clamp(24px, 4cqi, 56px); align-items: center; padding: 0 clamp(20px, 5cqi, 64px); }
.w5stp-photo { aspect-ratio: 4 / 3; max-height: 420px; overflow: hidden; border-radius: 18px; background: #284433; box-shadow: 0 30px 60px -36px rgba(0, 0, 0, .7); }
.w5stp-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.w5stp-n { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .08em; color: var(--w5stp-sage); }
.w5stp-h { margin: 10px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(26px, 3.4cqi, 40px); line-height: 1.12; }
.w5stp-text { margin: 14px 0 0; max-width: 42ch; font-size: 16px; line-height: 1.65; color: #d6dccf; }
.w5stp-tip { margin: 16px 0 0; padding-left: 14px; border-left: 2px solid var(--w5stp-sage); font-size: 14px; color: #e4e9dc; }
.w5stp-link { display: inline-flex; align-items: center; min-height: 44px; margin-top: 14px; color: #f1eee4; font-size: 14px; font-weight: 600; text-decoration: underline; text-decoration-color: var(--w5stp-sage); text-underline-offset: 5px; border-radius: 4px; }
.w5stp-link:focus-visible { outline: 3px solid var(--w5stp-sage); outline-offset: 2px; }
.w5stp-dots { display: flex; justify-content: center; gap: 4px; margin-top: 22px; }
.w5stp-dot { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.w5stp-dot span { width: 28px; height: 4px; border-radius: 4px; background: rgba(241, 238, 228, .3); transform: scaleX(.45); transition: transform .35s cubic-bezier(.3, 1.4, .5, 1), background-color .35s ease; }
.w5stp-dot[aria-current] span { background: var(--w5stp-sage); transform: scaleX(1); }
.w5stp-dot:not([aria-current]):hover span { background: rgba(241, 238, 228, .6); }
.w5stp-dot:focus-visible { outline: 3px solid var(--w5stp-sage); outline-offset: -4px; }
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5stp-root { scroll-snap-type: none !important; }
.w5stp-snap { display: none; }
.w5stp-stage { padding: 28px 0 12px; }
.w5stp-row { scroll-padding-inline: 0; }
.w5stp-panel { grid-template-columns: 1fr; align-items: start; gap: 18px; padding: 0 20px; }
.w5stp-dot span { transition: none; }
}
@media (prefers-reduced-motion: reduce) and (min-width: 640px) { .w5stp-panel { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: center; } }
@media (max-width: 639px) { .w5stp-text { font-size: 15px; } .w5stp-link { margin-top: 6px; } }
</style>
<script>
(function () {
var root = document.querySelector("[data-w5stp]");
if (!root) return;
// The box scrolls itself. For page scroll: remove height and overflow from .w5stp-root, set --w5stp-h to 100vh,
// then use window scroll events and (scrollY minus the track's page top) instead of root.scrollTop.
var $ = function (s) { return root.querySelector(s); };
var track = $(".w5stp-track"), stage = $(".w5stp-stage"), row = $(".w5stp-row");
var still = matchMedia("(prefers-reduced-motion: reduce), (max-width: 639px)");
var css = window.CSS && CSS.supports("animation-timeline: view()"); // CSS moves the row itself there
var raf = 0, seen = true;
var dots = root.querySelectorAll(".w5stp-dot"), n = dots.length;
function go(i) {
var b = matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
still.matches ? row.scrollTo({ left: row.children[i].offsetLeft - row.offsetLeft, behavior: b })
: root.scrollTo({ top: track.offsetTop + (span() * i) / (n - 1), behavior: b });
}
dots.forEach(function (d, i) { d.onclick = function () { go(i); }; });
function cl(x) { return Math.min(1, Math.max(0, x)) || 0; }
function span() { return track.offsetHeight - root.clientHeight; }
function paint() {
raf = 0;
var p = cl((root.scrollTop - track.offsetTop) / span()), flat = still.matches;
root.toggleAttribute("data-scrolled", root.scrollTop > 160);
if (!css) row.style.transform = flat ? "" : "translateX(" + -p * Math.max(0, row.offsetWidth - stage.clientWidth) + "px)";
var a = Math.round(flat ? row.scrollLeft / row.clientWidth : p * (n - 1));
dots.forEach(function (d, i) { i === a ? d.setAttribute("aria-current", "step") : d.removeAttribute("aria-current"); });
}
function queue() { if (seen && !raf) raf = requestAnimationFrame(paint); }
// Tabbing to a card off to the side scrolls the box to the point where that card is in view.
function focusIn(e) {
var card = e.target.closest(".w5stp-panel"), w = stage.clientWidth;
stage.scrollLeft = 0;
if (card && !still.matches) root.scrollTop = track.offsetTop + span() * cl((card.offsetLeft - (w - card.offsetWidth) / 2) / (row.offsetWidth - w));
}
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; queue(); });
io.observe(root);
root.addEventListener("scroll", queue, o);
row.addEventListener("focusin", focusIn, o);
row.addEventListener("scroll", queue, o);
window.addEventListener("resize", queue, o);
paint();
return function () {
cancelAnimationFrame(raf);
io.disconnect();
ac.abort();
};
})();
</script>
With reduced motion: Panels sit in a sideways row with no pinning or snapping of the box, and the bar buttons jump to a step instantly instead of gliding.
Running cost: One translateX per scroll frame on the panel row, plus an aria-current swap on five buttons; the photos load once at a fixed ratio.
- Set `--w5stp-run` for the scroll distance across all steps; the `.w5stp-snap` markers sit at even fractions of it, so add or remove one per step.
- Change `--w5stp-moss` and `--w5stp-sage` for the background and the accent used on labels and the active bar.
- Edit the `steps` array; its length sets the number of panels and bar buttons.
Pinned Pottery Gallery Row Sliding Sideways
A small pottery studio's new range laid out as one long shelf: the section pins while scrolling down carries a row of mixed portrait and landscape photos to the left, with a thin rule and a piece counter tracking how far along you are. It suits a portfolio or product range of five to eight items that deserves more room than a grid.
<section class="w5pgr-root" data-w5pgr tabindex="0" aria-label="Ember series gallery, scroll to move sideways">
<div class="w5pgr-track">
<div class="w5pgr-stage">
<div class="w5pgr-hint" aria-hidden="true"><span>Scroll inside</span></div>
<div class="w5pgr-head">
<div>
<p class="w5pgr-label">Halden Clay Works</p>
<h2 class="w5pgr-title">The Ember series</h2>
<p class="w5pgr-lede">Thrown, trimmed and fired in our back room kiln. Each piece is a little different from the photo.</p>
</div>
<div class="w5pgr-meter" aria-hidden="true">
<span class="w5pgr-count">01 / 05</span>
<span class="w5pgr-rule"><span class="w5pgr-fill"></span></span>
</div>
</div>
<ul class="w5pgr-row" role="list">
<li class="w5pgr-panel w5pgr-wide">
<a href="#" class="w5pgr-card">
<span class="w5pgr-frame"><img src="https://images.pexels.com/photos/9736720/pexels-photo-9736720.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Small round pots with a deep red-brown glaze arranged on a worn wooden board" width="900" height="675" loading="eager" /></span>
<span class="w5pgr-cap"><span class="w5pgr-name">Ember jars</span><span class="w5pgr-price">$38 each</span></span>
<span class="w5pgr-glaze">Iron red over raw clay</span>
</a>
</li><li class="w5pgr-panel w5pgr-tall">
<a href="#" class="w5pgr-card">
<span class="w5pgr-frame"><img src="https://images.pexels.com/photos/15122643/pexels-photo-15122643.jpeg?auto=compress&cs=tinysrgb&w=900" alt="A shelf of tall white ceramic vases in rounded and tapered shapes" width="900" height="675" loading="eager" /></span>
<span class="w5pgr-cap"><span class="w5pgr-name">Chalk vases</span><span class="w5pgr-price">$64 to $120</span></span>
<span class="w5pgr-glaze">Satin white, five shapes</span>
</a>
</li><li class="w5pgr-panel w5pgr-wide">
<a href="#" class="w5pgr-card">
<span class="w5pgr-frame"><img src="https://images.pexels.com/photos/8063803/pexels-photo-8063803.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Rows of unglazed white mugs with handles waiting on a studio shelf" width="900" height="675" loading="eager" /></span>
<span class="w5pgr-cap"><span class="w5pgr-name">Morning mugs</span><span class="w5pgr-price">$32</span></span>
<span class="w5pgr-glaze">Pick your glaze before firing</span>
</a>
</li><li class="w5pgr-panel w5pgr-wide">
<a href="#" class="w5pgr-card">
<span class="w5pgr-frame"><img src="https://images.pexels.com/photos/29282184/pexels-photo-29282184.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Handmade bowls in teal with a wave pattern and in burnt orange, close up in soft light" width="900" height="675" loading="eager" /></span>
<span class="w5pgr-cap"><span class="w5pgr-name">Tide bowls</span><span class="w5pgr-price">$46</span></span>
<span class="w5pgr-glaze">Teal slip, carved by hand</span>
</a>
</li><li class="w5pgr-panel w5pgr-tall">
<a href="#" class="w5pgr-card">
<span class="w5pgr-frame"><img src="https://images.pexels.com/photos/37472728/pexels-photo-37472728.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Black and white photo of a potter shaping a tall bottle at the wheel among rows of unfired pots" width="900" height="675" loading="eager" /></span>
<span class="w5pgr-cap"><span class="w5pgr-name">Made to order</span><span class="w5pgr-price">From $90</span></span>
<span class="w5pgr-glaze">Commissions open in March</span>
</a>
</li>
<li class="w5pgr-panel w5pgr-end">
<p class="w5pgr-endtext">Open studio every Saturday, 10 to 4. Pick pieces off the shelf and see the next firing.</p>
<a href="#" class="w5pgr-btn">Plan a visit</a>
</li>
</ul>
</div>
</div>
</section>
<style>
/* Change these: --w5pgr-paper (background), --w5pgr-rust (accent), --w5pgr-run (scroll distance for the whole row),
--w5pgr-img (photo height), and AUTO in the script (demo scroll speed, 0 to turn it off). */
.w5pgr-root { --w5pgr-h: 600px; --w5pgr-run: 1400px; position: relative; height: var(--w5pgr-h); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
.w5pgr-root *, .w5pgr-root *::before, .w5pgr-root *::after { box-sizing: border-box; }
.w5pgr-track { height: calc(var(--w5pgr-h) + var(--w5pgr-run)); }
.w5pgr-stage { position: sticky; top: 0; height: var(--w5pgr-h); overflow: hidden; container-type: inline-size; }
.w5pgr-row { position: relative; display: flex; width: max-content; will-change: transform; }
.w5pgr-hint { position: absolute; top: 12px; left: 0; right: 0; z-index: 5; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }
.w5pgr-hint span { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.w5pgr-root[data-scrolled] .w5pgr-hint { opacity: 0; }
@keyframes w5pgr-slide { to { transform: translateX(calc(-100% + 100cqi)); } }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5pgr-track { view-timeline: --w5pgr-tl block; }
.w5pgr-row { animation: w5pgr-slide linear both; animation-timeline: --w5pgr-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5pgr-track { height: auto; }
.w5pgr-stage { position: static; height: auto; min-height: var(--w5pgr-h); overflow: visible; }
.w5pgr-hint { display: none; }
.w5pgr-row { width: auto; overflow-x: auto; scroll-snap-type: x mandatory; transform: none !important; animation: none !important; scrollbar-width: thin; scroll-padding-inline: clamp(20px, 5cqi, 64px); }
.w5pgr-panel { scroll-snap-align: start; }
}
.w5pgr-root { --w5pgr-paper: #f2ebe0; --w5pgr-rust: #9a4424; --w5pgr-img: 290px; background: var(--w5pgr-paper); color: #2b211a; font-family: ui-sans-serif, system-ui, sans-serif; scrollbar-color: #c9b9a3 transparent; }
.w5pgr-root:focus-visible { outline: 3px solid var(--w5pgr-rust); outline-offset: -3px; }
.w5pgr-hint span { background: #2b211a; color: #f2ebe0; }
.w5pgr-stage { display: flex; flex-direction: column; justify-content: center; gap: 28px; }
.w5pgr-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 0 clamp(20px, 5cqi, 64px); }
.w5pgr-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--w5pgr-rust); }
.w5pgr-title { margin: 8px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(28px, 4.2cqi, 44px); line-height: 1.1; }
.w5pgr-lede { margin: 10px 0 0; max-width: 46ch; font-size: 15px; line-height: 1.6; color: #5a4a3c; }
.w5pgr-meter { display: grid; justify-items: end; gap: 10px; flex: 0 0 auto; }
.w5pgr-count { font-size: 13px; font-weight: 600; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.w5pgr-rule { display: block; width: 160px; height: 2px; background: #d9ccba; overflow: hidden; }
.w5pgr-fill { display: block; height: 100%; background: var(--w5pgr-rust); transform: scaleX(0); transform-origin: 0 50%; }
.w5pgr-row { margin: 0; padding: 0 clamp(20px, 5cqi, 64px); list-style: none; gap: 28px; align-items: flex-start; }
.w5pgr-panel { flex: 0 0 auto; }
.w5pgr-card { display: block; color: inherit; text-decoration: none; border-radius: 6px; }
.w5pgr-card:focus-visible { outline: 3px solid var(--w5pgr-rust); outline-offset: 6px; }
.w5pgr-frame { display: block; height: var(--w5pgr-img); overflow: hidden; border-radius: 4px; background: #e2d6c4; box-shadow: 0 18px 40px -28px rgba(60, 35, 15, .55); }
.w5pgr-wide .w5pgr-frame { width: calc(var(--w5pgr-img) * 4 / 3); }
.w5pgr-tall .w5pgr-frame { width: calc(var(--w5pgr-img) * 3 / 4); }
.w5pgr-frame img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .6s cubic-bezier(.2, .7, .2, 1); }
.w5pgr-card:hover img, .w5pgr-card:focus-visible img { transform: scale(1.04); }
.w5pgr-cap { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; font-size: 15px; }
.w5pgr-name { font-weight: 600; }
.w5pgr-price { color: #5a4a3c; font-variant-numeric: tabular-nums; }
.w5pgr-glaze { display: block; margin-top: 4px; font-size: 13px; color: #6b5a4a; }
.w5pgr-end { align-self: stretch; width: 260px; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 0 8px; border-left: 1px solid #d9ccba; padding-left: 28px; height: var(--w5pgr-img); }
.w5pgr-endtext { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 20px; line-height: 1.4; }
.w5pgr-btn { align-self: flex-start; display: inline-flex; align-items: center; min-height: 44px; padding: 0 20px; border-radius: 999px; background: #2b211a; color: #f2ebe0; font-size: 14px; font-weight: 600; text-decoration: none; }
.w5pgr-btn:hover { background: var(--w5pgr-rust); }
.w5pgr-btn:focus-visible { outline: 3px solid var(--w5pgr-rust); outline-offset: 3px; }
@keyframes w5pgr-grow { to { transform: scaleX(1); } }
@supports (animation-timeline: view()) {
@media (min-width: 640px) and (prefers-reduced-motion: no-preference) {
.w5pgr-fill { animation: w5pgr-grow linear both; animation-timeline: --w5pgr-tl; animation-range: contain 0% contain 100%; }
}
}
@media (max-width: 639px), (prefers-reduced-motion: reduce) {
.w5pgr-root { --w5pgr-img: 250px; }
.w5pgr-stage { justify-content: center; padding: 32px 0; }
.w5pgr-meter { display: none; }
.w5pgr-row { padding-bottom: 12px; }
.w5pgr-frame img { transition: none; }
}
@media (max-width: 639px) { .w5pgr-wide .w5pgr-frame { width: min(calc(var(--w5pgr-img) * 4 / 3), 78vw); } }
</style>
<script>
(function () {
var root = document.querySelector("[data-w5pgr]");
if (!root) return;
// The box scrolls itself. For page scroll: remove height and overflow from .w5pgr-root, set --w5pgr-h to 100vh,
// then use window scroll events and (scrollY minus the track's page top) instead of root.scrollTop.
var AUTO = 80; // demo scroll speed in px per second until someone scrolls; 0 turns it off
var $ = function (s) { return root.querySelector(s); };
var track = $(".w5pgr-track"), stage = $(".w5pgr-stage"), row = $(".w5pgr-row");
var still = matchMedia("(prefers-reduced-motion: reduce), (max-width: 639px)");
var css = window.CSS && CSS.supports("animation-timeline: view()"); // CSS moves the row itself there
var af = requestAnimationFrame, caf = cancelAnimationFrame, raf = 0, demo = 0, last = 0, pos = 0, seen = true, done = !AUTO;
var fill = $(".w5pgr-fill"), count = $(".w5pgr-count"), n = row.querySelectorAll("img").length;
function cl(x) { return Math.min(1, Math.max(0, x)) || 0; }
function span() { return track.offsetHeight - root.clientHeight; }
function shift(el, p, flat) {
if (!css) el.style.transform = flat ? "" : "translateX(" + -p * Math.max(0, el.offsetWidth - stage.clientWidth) + "px)";
}
function paint() {
raf = 0;
var p = cl((root.scrollTop - track.offsetTop) / span()), flat = still.matches;
root.toggleAttribute("data-scrolled", root.scrollTop > 160);
shift(row, p, flat);
if (!css) fill.style.transform = flat ? "" : "scaleX(" + p + ")";
count.textContent = "0" + (Math.round(p * (n - 1)) + 1) + " / 0" + n;
}
function queue() { if (!raf) raf = af(paint); }
function step(now) {
var dt = last ? Math.min(now - last, 50) : 0;
last = now;
pos += (AUTO * dt) / 1000;
if (pos >= root.scrollHeight - root.clientHeight) { done = true; demo = 0; return; }
root.scrollTop = pos;
demo = af(step);
}
function start() { if (!done && seen && !demo && !still.matches) { last = 0; pos = root.scrollTop; demo = af(step); } }
function stop() { caf(demo); demo = 0; }
function hand() { done = true; stop(); }
// Tabbing to a card off to the side scrolls the box to the point where that card is in view.
function focusIn(e) {
var card = e.target.closest(".w5pgr-panel");
stage.scrollLeft = 0;
if (!card || still.matches) return;
hand();
var w = stage.clientWidth;
root.scrollTop = track.offsetTop + span() * cl((card.offsetLeft - (w - card.offsetWidth) / 2) / (row.offsetWidth - w));
}
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; seen ? start() : stop(); });
io.observe(root);
["wheel", "touchstart", "pointerdown", "keydown"].forEach(function (ev) { root.addEventListener(ev, hand, o); });
root.addEventListener("scroll", queue, o);
row.addEventListener("focusin", focusIn, o);
row.addEventListener("scroll", queue, o);
window.addEventListener("resize", queue, o);
paint();
start();
return function () {
stop();
caf(raf);
io.disconnect();
ac.abort();
};
})();
</script>
With reduced motion: The section stops pinning and the photos sit in an ordinary row that you swipe or scroll sideways at your own pace.
Running cost: One translateX on a single row, driven by a view timeline where supported or one rAF-throttled write per scroll elsewhere.
- Set `--w5pgr-run` to change how much scrolling the whole row takes; a bigger value makes it travel slower.
- Change `--w5pgr-img` to resize every photo at once, and swap `w5pgr-wide` or `w5pgr-tall` on a panel to change its shape.
- Recolour with `--w5pgr-paper` and `--w5pgr-rust`, and edit the pieces in the `pieces` array.
Snap Photo Strip with Centre Card Growing
A row of holiday houses that snaps each card to the middle, where it grows to full size and its photo brightens while the neighbours shrink back and dim. It opens with the second house centred so both sides of the strip show. The growth follows each card's own view timeline across the row, so it tracks a swipe exactly.
<section class="w5ctr-root" data-w5ctr aria-labelledby="w5ctr-title">
<div class="w5ctr-head">
<p class="w5ctr-label">Saltmarsh Stays</p>
<h2 class="w5ctr-title" id="w5ctr-title">Six houses at the edge of the map</h2>
</div>
<ul class="w5ctr-row" id="w5ctr-row" role="list" tabindex="0" aria-label="Holiday houses, scroll sideways">
<li class="w5ctr-card">
<a href="#" class="w5ctr-in">
<span class="w5ctr-photo"><img src="https://images.pexels.com/photos/27390890/pexels-photo-27390890.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A small stone cottage with a turf roof above a rocky shore under an evening sky" width="700" height="875" loading="eager" /><span class="w5ctr-dim" aria-hidden="true"></span></span>
<span class="w5ctr-name">The Bothy</span>
<span class="w5ctr-meta">Carrick Point · Sleeps 2</span>
<span class="w5ctr-price">from $140 a night</span>
</a>
</li><li class="w5ctr-card">
<a href="#" class="w5ctr-in">
<span class="w5ctr-photo"><img src="https://images.pexels.com/photos/38235551/pexels-photo-38235551.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A white house on a grassy dune above a pebble beach and grey sea" width="700" height="875" loading="eager" /><span class="w5ctr-dim" aria-hidden="true"></span></span>
<span class="w5ctr-name">Dune House</span>
<span class="w5ctr-meta">Hessel Bay · Sleeps 6</span>
<span class="w5ctr-price">from $260 a night</span>
</a>
</li><li class="w5ctr-card">
<a href="#" class="w5ctr-in">
<span class="w5ctr-photo"><img src="https://images.pexels.com/photos/5823211/pexels-photo-5823211.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A lone house on top of a dark green hill above a quiet shore" width="700" height="875" loading="eager" /><span class="w5ctr-dim" aria-hidden="true"></span></span>
<span class="w5ctr-name">Hill End</span>
<span class="w5ctr-meta">Morrow Head · Sleeps 4</span>
<span class="w5ctr-price">from $190 a night</span>
</a>
</li><li class="w5ctr-card">
<a href="#" class="w5ctr-in">
<span class="w5ctr-photo"><img src="https://images.pexels.com/photos/6916146/pexels-photo-6916146.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A pale yellow house with a red roof on rocks, lit by a pink sunset" width="700" height="875" loading="eager" /><span class="w5ctr-dim" aria-hidden="true"></span></span>
<span class="w5ctr-name">Signal Cottage</span>
<span class="w5ctr-meta">Ness Harbour · Sleeps 4</span>
<span class="w5ctr-price">from $210 a night</span>
</a>
</li><li class="w5ctr-card">
<a href="#" class="w5ctr-in">
<span class="w5ctr-photo"><img src="https://images.pexels.com/photos/36707272/pexels-photo-36707272.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A red wooden boathouse at the edge of a still lake below misty green hills" width="700" height="875" loading="eager" /><span class="w5ctr-dim" aria-hidden="true"></span></span>
<span class="w5ctr-name">The Boathouse</span>
<span class="w5ctr-meta">Lake Ferrin · Sleeps 2</span>
<span class="w5ctr-price">from $150 a night</span>
</a>
</li><li class="w5ctr-card">
<a href="#" class="w5ctr-in">
<span class="w5ctr-photo"><img src="https://images.pexels.com/photos/19680864/pexels-photo-19680864.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A farmhouse among cypress trees on rolling green fields in morning mist" width="700" height="875" loading="eager" /><span class="w5ctr-dim" aria-hidden="true"></span></span>
<span class="w5ctr-name">Upper Fold Farm</span>
<span class="w5ctr-meta">Calder Vale · Sleeps 8</span>
<span class="w5ctr-price">from $320 a night</span>
</a>
</li>
</ul>
<div class="w5ctr-btns">
<button type="button" class="w5ctr-prev" aria-controls="w5ctr-row" aria-label="Previous house"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M12.5 4.5 7 10l5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="w5ctr-next" aria-controls="w5ctr-row" aria-label="Next house"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M7.5 4.5 13 10l-5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
</div>
</section>
<style>
/* Change these: --w5ctr-clay (background), --w5ctr-card (card width), --w5ctr-small (how far side cards shrink,
also SMALL in the script), and START in the script (which card is centred on load, counting from 0). */
.w5ctr-root { --w5ctr-clay: #7b3421; --w5ctr-card: 280px; --w5ctr-small: .84; padding: 52px 0 40px; background: var(--w5ctr-clay); color: #fbefe4; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
.w5ctr-root *, .w5ctr-root *::before { box-sizing: border-box; }
.w5ctr-head { padding: 0 20px; text-align: center; }
.w5ctr-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: #f4c8a8; }
.w5ctr-title { margin: 8px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(28px, 4vw, 40px); line-height: 1.12; }
.w5ctr-row { display: flex; gap: 8px; margin: 26px 0 0; padding: 10px calc(50% - var(--w5ctr-card) / 2) 14px; list-style: none; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.w5ctr-row::-webkit-scrollbar { display: none; }
.w5ctr-row:focus-visible { outline: 3px solid #f4c8a8; outline-offset: -3px; }
.w5ctr-card { flex: 0 0 var(--w5ctr-card); scroll-snap-align: center; view-timeline: --w5ctr-card inline; }
.w5ctr-in { display: block; color: inherit; text-decoration: none; text-align: center; border-radius: 16px; transform: scale(var(--w5ctr-small)); will-change: transform; }
.w5ctr-in:focus-visible { outline: 3px solid #f4c8a8; outline-offset: 6px; }
.w5ctr-photo { position: relative; display: block; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 16px; background: #5e2718; box-shadow: 0 26px 50px -30px rgba(20, 5, 0, .8); }
.w5ctr-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.w5ctr-dim { position: absolute; inset: 0; background: #3a150b; opacity: .45; }
.w5ctr-name { display: block; margin-top: 16px; font-family: Georgia, "Times New Roman", serif; font-size: 22px; }
.w5ctr-meta { display: block; margin-top: 4px; font-size: 14px; color: #f1d8c6; }
.w5ctr-price { display: block; margin-top: 4px; font-size: 14px; font-weight: 600; }
.w5ctr-btns { display: flex; justify-content: center; gap: 12px; margin-top: 18px; }
.w5ctr-btns button { display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid rgba(251, 239, 228, .4); border-radius: 50%; background: transparent; color: #fbefe4; cursor: pointer; transition: background-color .2s ease; }
.w5ctr-btns button:hover { background: rgba(251, 239, 228, .12); }
.w5ctr-btns button[aria-disabled="true"] { opacity: .35; cursor: default; }
.w5ctr-btns button:focus-visible { outline: 3px solid #f4c8a8; outline-offset: 3px; }
@keyframes w5ctr-grow { 0%, 100% { transform: scale(var(--w5ctr-small)); } 50% { transform: scale(1); } }
@keyframes w5ctr-lift { 0%, 100% { opacity: .45; } 50% { opacity: 0; } }
@supports (animation-timeline: view()) {
@media (prefers-reduced-motion: no-preference) {
.w5ctr-in { animation: w5ctr-grow linear both; animation-timeline: --w5ctr-card; }
.w5ctr-dim { animation: w5ctr-lift linear both; animation-timeline: --w5ctr-card; }
}
}
@media (prefers-reduced-motion: reduce) {
.w5ctr-in { transform: none; }
.w5ctr-dim { opacity: 0; }
.w5ctr-row { gap: 20px; }
.w5ctr-btns button { transition: none; }
}
@media (max-width: 639px) { .w5ctr-root { --w5ctr-card: 240px; } }
</style>
<script>
(function () {
var root = document.querySelector("[data-w5ctr]");
if (!root) return;
var $ = function (s) { return root.querySelector(s); };
var row = $(".w5ctr-row"), prev = $(".w5ctr-prev"), next = $(".w5ctr-next");
var rm = matchMedia("(prefers-reduced-motion: reduce)");
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var go = function (d) { row.scrollBy({ left: d * row.clientWidth * 0.8, behavior: rm.matches ? "auto" : "smooth" }); };
var START = 1, SMALL = 0.84; // card centred on load, and side card scale
var cards = [].slice.call(row.children), css = window.CSS && CSS.supports("animation-timeline: view()");
var seen = true, raf = 0;
var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; });
io.observe(root);
// Fallback for browsers without view timelines: scale each card by its distance from the centre.
function grow() {
raf = 0;
var mid = row.scrollLeft + row.clientWidth / 2;
cards.forEach(function (c) {
var d = Math.min(1, Math.abs(c.offsetLeft - row.offsetLeft + c.offsetWidth / 2 - mid) / (c.offsetWidth + 8));
c.firstElementChild.style.transform = "scale(" + (1 - (1 - SMALL) * d) + ")";
c.querySelector(".w5ctr-dim").style.opacity = 0.45 * d;
});
}
var c0 = cards[START];
row.scrollLeft = c0.offsetLeft - row.offsetLeft - (row.clientWidth - c0.offsetWidth) / 2;
function paint() {
var max = row.scrollWidth - row.clientWidth, x = row.scrollLeft;
prev.setAttribute("aria-disabled", String(x < 4));
next.setAttribute("aria-disabled", String(x > max - 4));
if (!css && !rm.matches && seen && !raf) raf = requestAnimationFrame(grow);
}
prev.addEventListener("click", function () { go(-1); }, o);
next.addEventListener("click", function () { go(1); }, o);
row.addEventListener("scroll", paint, o);
window.addEventListener("resize", paint, o);
paint();
return function () {
ac.abort();
io.disconnect();
cancelAnimationFrame(raf);
};
})();
</script>
With reduced motion: Every card sits at full size with no dimming, in a plain snapping row with a little more space between them.
Running cost: Each card animates only transform and an overlay's opacity on the compositor; the fallback writes them once per frame while scrolling.
- Set `--w5ctr-small` (and `SMALL` in the script fallback) for how far side cards shrink.
- Change `--w5ctr-card` for the card width and `START` in the script for the card centred on load.
- Edit names, places and prices in the `homes` array, and the background with `--w5ctr-clay`.
Snap Scroll Bread Shelf with Arrow Buttons
A bakery's weekly loaves on a sideways shelf that lines up with the page heading on the left and runs off the right edge. Cards snap into place as you swipe, round arrow buttons step through them and grey out at either end, and a thin bar below fills to show how much of the shelf you have seen.
<section class="w5shf-root" data-w5shf aria-labelledby="w5shf-title">
<div class="w5shf-head">
<div>
<p class="w5shf-label">Fennick Bakehouse</p>
<h2 class="w5shf-title" id="w5shf-title">On the shelf this week</h2>
<p class="w5shf-lede">Order by Thursday night and we hold your loaves at the counter until noon on Saturday.</p>
</div>
<div class="w5shf-btns">
<button type="button" class="w5shf-prev" aria-controls="w5shf-row" aria-label="Previous loaves"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M12.5 4.5 7 10l5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="w5shf-next" aria-controls="w5shf-row" aria-label="Next loaves"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M7.5 4.5 13 10l-5.5 5.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
</div>
</div>
<ul class="w5shf-row" id="w5shf-row" role="list" tabindex="0" aria-label="Breads, scroll sideways">
<li class="w5shf-card">
<div class="w5shf-photo"><img src="https://images.pexels.com/photos/32935771/pexels-photo-32935771.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Scored sourdough loaves with a deep golden crust, close up" width="700" height="875" loading="eager" /></div>
<div class="w5shf-line"><h3 class="w5shf-name">Country sourdough</h3><span class="w5shf-price">$9</span></div>
<p class="w5shf-note">Three day ferment, dark bake, open crumb.</p>
<a href="#" class="w5shf-add">Reserve<span class="w5shf-sr"> Country sourdough</span></a>
</li><li class="w5shf-card">
<div class="w5shf-photo"><img src="https://images.pexels.com/photos/8599725/pexels-photo-8599725.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Thick slices of dark seeded rye bread on a white surface" width="700" height="875" loading="eager" /></div>
<div class="w5shf-line"><h3 class="w5shf-name">Seeded rye</h3><span class="w5shf-price">$8</span></div>
<p class="w5shf-note">Dense and sour, best sliced thin with butter.</p>
<a href="#" class="w5shf-add">Reserve<span class="w5shf-sr"> Seeded rye</span></a>
</li><li class="w5shf-card">
<div class="w5shf-photo"><img src="https://images.pexels.com/photos/34936588/pexels-photo-34936588.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Golden baguettes stacked together on a bakery shelf" width="700" height="875" loading="eager" /></div>
<div class="w5shf-line"><h3 class="w5shf-name">Morning baguette</h3><span class="w5shf-price">$4</span></div>
<p class="w5shf-note">Out of the oven at seven, gone by ten.</p>
<a href="#" class="w5shf-add">Reserve<span class="w5shf-sr"> Morning baguette</span></a>
</li><li class="w5shf-card">
<div class="w5shf-photo"><img src="https://images.pexels.com/photos/33657315/pexels-photo-33657315.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Squares of focaccia topped with cherry tomatoes and rosemary in a pan" width="700" height="875" loading="eager" /></div>
<div class="w5shf-line"><h3 class="w5shf-name">Tomato focaccia</h3><span class="w5shf-price">$7</span></div>
<p class="w5shf-note">Olive oil, sea salt and roasted tomatoes.</p>
<a href="#" class="w5shf-add">Reserve<span class="w5shf-sr"> Tomato focaccia</span></a>
</li><li class="w5shf-card">
<div class="w5shf-photo"><img src="https://images.pexels.com/photos/30632209/pexels-photo-30632209.jpeg?auto=compress&cs=tinysrgb&w=700" alt="A whole grain loaf covered in seeds held over a checked cloth" width="700" height="875" loading="eager" /></div>
<div class="w5shf-line"><h3 class="w5shf-name">Granary tin</h3><span class="w5shf-price">$7</span></div>
<p class="w5shf-note">Malted flakes for a soft, nutty sandwich loaf.</p>
<a href="#" class="w5shf-add">Reserve<span class="w5shf-sr"> Granary tin</span></a>
</li><li class="w5shf-card">
<div class="w5shf-photo"><img src="https://images.pexels.com/photos/31132628/pexels-photo-31132628.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Spiral morning buns on a tray in a bakery window behind a handwritten label" width="700" height="875" loading="eager" /></div>
<div class="w5shf-line"><h3 class="w5shf-name">Morning buns</h3><span class="w5shf-price">$4.75</span></div>
<p class="w5shf-note">Orange zest and cinnamon, Saturdays only.</p>
<a href="#" class="w5shf-add">Reserve<span class="w5shf-sr"> Morning buns</span></a>
</li>
</ul>
<div class="w5shf-bar" aria-hidden="true"><span class="w5shf-fill"></span></div>
</section>
<style>
/* Change these: --w5shf-flour (background), --w5shf-crust (accent), --w5shf-card (card width; the photo keeps 4:5),
--w5shf-max (content width the row lines up with). */
.w5shf-root { --w5shf-flour: #f1e8d8; --w5shf-crust: #7a3c1b; --w5shf-card: 260px; --w5shf-max: 1160px; --w5shf-pad: max(20px, calc((100% - var(--w5shf-max)) / 2)); padding: 56px 0 48px; background: var(--w5shf-flour); color: #2d231a; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
.w5shf-root *, .w5shf-root *::before { box-sizing: border-box; }
.w5shf-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 0 var(--w5shf-pad); }
.w5shf-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--w5shf-crust); }
.w5shf-title { margin: 8px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(28px, 4vw, 40px); line-height: 1.12; }
.w5shf-lede { margin: 10px 0 0; max-width: 48ch; font-size: 15px; line-height: 1.6; color: #5b4a3a; }
.w5shf-btns { display: flex; gap: 10px; flex: 0 0 auto; }
.w5shf-btns button { display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid #cdbba1; border-radius: 50%; background: #fbf6ee; color: #2d231a; cursor: pointer; transition: background-color .2s ease, transform .2s ease; }
.w5shf-btns button:hover { background: #fff; }
.w5shf-btns button:active { transform: scale(.94); }
.w5shf-btns button[aria-disabled="true"] { opacity: .4; cursor: default; }
.w5shf-btns button:focus-visible, .w5shf-row:focus-visible, .w5shf-add:focus-visible { outline: 3px solid var(--w5shf-crust); outline-offset: 3px; }
.w5shf-row { display: flex; gap: 22px; margin: 28px 0 0; padding: 4px var(--w5shf-pad) 8px; list-style: none; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: var(--w5shf-pad); scrollbar-width: none; overscroll-behavior-x: contain; }
.w5shf-row::-webkit-scrollbar { display: none; }
.w5shf-card { position: relative; flex: 0 0 var(--w5shf-card); scroll-snap-align: start; }
.w5shf-photo { aspect-ratio: 4 / 5; overflow: hidden; border-radius: 14px; background: #e3d5bf; }
.w5shf-photo img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .6s cubic-bezier(.2, .7, .2, 1); }
.w5shf-card:hover img, .w5shf-card:focus-within img { transform: scale(1.04); }
.w5shf-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 14px; }
.w5shf-name { margin: 0; font-size: 16px; font-weight: 600; }
.w5shf-price { font-size: 15px; font-variant-numeric: tabular-nums; color: #5b4a3a; }
.w5shf-note { margin: 6px 0 0; font-size: 14px; line-height: 1.5; color: #5b4a3a; }
.w5shf-add { display: inline-flex; align-items: center; min-height: 40px; margin-top: 4px; font-size: 14px; font-weight: 600; color: var(--w5shf-crust); text-decoration: underline; text-underline-offset: 4px; border-radius: 4px; }
.w5shf-bar { height: 2px; margin: 18px var(--w5shf-pad) 0; background: #dccdb6; overflow: hidden; }
.w5shf-fill { display: block; height: 100%; background: var(--w5shf-crust); transform: scaleX(.3); transform-origin: 0 50%; }
.w5shf-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 639px) { .w5shf-head { flex-direction: column; align-items: flex-start; } .w5shf-root { --w5shf-card: 230px; } }
@media (prefers-reduced-motion: reduce) { .w5shf-photo img, .w5shf-btns button { transition: none; } }
</style>
<script>
(function () {
var root = document.querySelector("[data-w5shf]");
if (!root) return;
var $ = function (s) { return root.querySelector(s); };
var row = $(".w5shf-row"), prev = $(".w5shf-prev"), next = $(".w5shf-next");
var rm = matchMedia("(prefers-reduced-motion: reduce)");
var ac = new AbortController(), o = { passive: true, signal: ac.signal };
var go = function (d) { row.scrollBy({ left: d * row.clientWidth * 0.8, behavior: rm.matches ? "auto" : "smooth" }); };
function paint() {
var max = row.scrollWidth - row.clientWidth, x = row.scrollLeft;
prev.setAttribute("aria-disabled", String(x < 4));
next.setAttribute("aria-disabled", String(x > max - 4));
var seen = row.clientWidth / row.scrollWidth;
$(".w5shf-fill").style.transform = "scaleX(" + (seen + (1 - seen) * (max > 0 ? x / max : 1)) + ")";
}
prev.addEventListener("click", function () { go(-1); }, o);
next.addEventListener("click", function () { go(1); }, o);
row.addEventListener("scroll", paint, o);
window.addEventListener("resize", paint, o);
paint();
return function () {
ac.abort();
};
})();
</script>
With reduced motion: The arrow buttons jump straight to the next cards instead of gliding, and the photo zoom on hover is switched off.
Running cost: Scrolling and snapping are native; the script only flips two attributes and one scaleX on the progress bar per scroll event.
- Change `--w5shf-card` for the card width; photos keep a 4:5 shape so nothing jumps while they load.
- Set `--w5shf-max` to the width of your page container so the first card lines up with the heading.
- Recolour with `--w5shf-flour` and `--w5shf-crust`, and edit the loaves in the `loaves` array.
Performance notes
The pinned row moves with one translateX on a single wide layer. In browsers with scroll-driven animations it follows a view() timeline with no script at all; elsewhere a passive scroll listener writes that one transform once per frame while the section is on screen.
Snap rows need no script to scroll. The buttons only call scrollBy, and scroll-snap does the settling, so nothing is measured while a visitor swipes. Images in long rows load lazily with fixed dimensions.
Questions
How do I scroll a section horizontally when the user scrolls down?
Make a tall outer section, put a sticky inner box in it at full screen height, and translate the wide row inside by the section's scroll progress. CSS scroll-driven animations can do this alone in supporting browsers; a short script covers the rest.
Which browsers support scroll snap?
MDN lists scroll-snap-type in Chrome from 69, Firefox from 99 and Safari from 11, so a snapping horizontal row works in every current browser.
Can keyboard users use a horizontal scroll section?
Yes, when the row is focusable or has previous and next buttons, and every card inside is a normal link or button. Tabbing to a card that is off screen should scroll it into view, which the snap rows here do natively.
Does horizontal scrolling work on phones?
Swiping a snap row feels natural on touch. A pinned row driven by vertical scroll works too, but the pieces here switch to the swipe version on small screens, which is easier to control with a thumb.
More collections: Scrollytelling Sections in HTML, CSS and React, Stacking Cards on Scroll, Expanding Cards and Image Panels. All scroll effects. Build your site free to have a full site built around them.
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App