Scroll-drawn timeline
A company history timeline whose center line draws itself as you scroll, with each milestone popping in and its dot lighting up when the line reaches it.
"use client";
import { useEffect, useRef, useState, type CSSProperties } from "react";
import "./scroll-timeline.css";
const EVENTS = [
{
year: "2017",
title: "Two people, one borrowed desk",
text: "We started as a two-person studio in a shared office, building websites for local bakeries and bike shops.",
},
{
year: "2019",
title: "First product: Grid",
text: "A small tool we made for ourselves to plan layouts. Ten thousand designers signed up in the first month.",
},
{
year: "2021",
title: "Remote-first, 14 countries",
text: "We closed the office and hired wherever good people lived. The team grew to 32.",
},
{
year: "2023",
title: "Grid 2.0 and real-time editing",
text: "Teams could finally work on the same page at once. Usage tripled within a year.",
},
{
year: "2025",
title: "Profitable and independent",
text: "No outside investors, no exit plan. Just a calm company that builds tools people pay for.",
},
{
year: "2026",
title: "Now: open-sourcing the core",
text: "The layout engine behind Grid is now free for anyone to use and improve.",
},
];
/** Nearest scrolling ancestor, or the window. Lets the piece work inside any scroll box. */
function scrollParent(el: HTMLElement | null): HTMLElement | Window {
for (let p = el?.parentElement; p; p = p.parentElement) {
const o = getComputedStyle(p).overflowY;
if (o === "auto" || o === "scroll") return p;
}
return window;
}
/**
* ScrollTimeline
* - Progress = how far the timeline's top has passed the middle of the viewport, divided by its height.
* - The line's scaleY is that progress; each item is "reached" when the line passes its dot.
*/
export function ScrollTimeline({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const list = useRef<HTMLOListElement>(null);
const [progress, setProgress] = useState(0);
const [reached, setReached] = useState<number>(-1);
useEffect(() => {
const el = list.current;
if (!el) return;
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
const raf = requestAnimationFrame(() => {
setProgress(1);
setReached(EVENTS.length);
});
return () => cancelAnimationFrame(raf);
}
const sp = scrollParent(el);
let raf = 0;
const update = () => {
raf = 0;
const box = el.getBoundingClientRect();
const viewTop = sp instanceof Window ? 0 : sp.getBoundingClientRect().top;
const viewH = sp instanceof Window ? innerHeight : sp.clientHeight;
const mid = viewTop + viewH * 0.6;
const p = Math.min(1, Math.max(0, (mid - box.top) / box.height));
setProgress(p);
const dots = el.querySelectorAll<HTMLElement>("[data-dot]");
let r = -1;
dots.forEach((d, i) => d.getBoundingClientRect().top < mid && (r = i));
setReached(r);
};
const onScroll = () => (raf ||= requestAnimationFrame(update));
onScroll();
sp.addEventListener("scroll", onScroll, { passive: true });
addEventListener("resize", onScroll);
return () => {
sp.removeEventListener("scroll", onScroll);
removeEventListener("resize", onScroll);
cancelAnimationFrame(raf);
};
}, []);
return (
<section className="gu-tl" data-theme={theme}>
<header>
<h2>Nine years, one idea.</h2>
<p>
Scroll to follow how a two-person studio became a calm, independent
software company.
</p>
</header>
<div className="gu-tl__wrap" style={{ "--p": progress } as CSSProperties}>
<span className="gu-tl__rail" aria-hidden="true" />
<ol ref={list} className="gu-tl__list">
{EVENTS.map((e, i) => (
<li
key={e.year}
data-side={i % 2 ? "right" : "left"}
data-on={i <= reached ? "" : undefined}
>
<span className="gu-tl__dot" data-dot aria-hidden="true" />
<div className="gu-tl__card">
<time>{e.year}</time>
<h3>{e.title}</h3>
<p>{e.text}</p>
</div>
</li>
))}
</ol>
</div>
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Scroll-drawn timeline
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A company history timeline section. A vertical line runs down the middle; as you scroll, an orange line draws down it, and each milestone card rises and brightens while its dot fills orange and pops when the line reaches it. Cards alternate left and right.
## Layout and look
- Section on Cream (dark Ink). Centered headline "Nine years, one idea." (clamp 38–88px, weight 900, tracking -0.05em) and a muted intro.
- Timeline max 1000px: 3px gray rail at center with the orange progress over it; two columns with 64px gap; cards alternate sides (left ones right-aligned).
- Dots: 22px circles with a 3px border; filled orange and scaled 1.25 when reached.
- Cards: radius 24px, hairline border; big year (clamp 32–51px, weight 900; orange once reached), title (19px, weight 800), muted paragraph.
- Under 700px container width: rail and dots on the left, all cards in one column.
## Behavior and motion
1. Progress = (60% of the viewport − timeline top) / timeline height, clamped 0–1, read on scroll with requestAnimationFrame. Works inside any scrolling container.
2. The rail uses transform: scaleY(progress) from the top.
3. A milestone is "reached" when its dot is above the 60% line: card opacity 0.25 → 1, translateY 24px → 0 (800ms cubic-bezier(0.16, 1, 0.3, 1)); dot springs.
## Accessibility
- An ordered list with <time>; the content is all present in the HTML (only the visual emphasis changes).
- prefers-reduced-motion: fully drawn, every card visible.
## Props
theme. Edit EVENTS.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### ScrollTimeline.tsx
```tsx
"use client";
import { useEffect, useRef, useState, type CSSProperties } from "react";
import "./scroll-timeline.css";
const EVENTS = [
{
year: "2017",
title: "Two people, one borrowed desk",
text: "We started as a two-person studio in a shared office, building websites for local bakeries and bike shops.",
},
{
year: "2019",
title: "First product: Grid",
text: "A small tool we made for ourselves to plan layouts. Ten thousand designers signed up in the first month.",
},
{
year: "2021",
title: "Remote-first, 14 countries",
text: "We closed the office and hired wherever good people lived. The team grew to 32.",
},
{
year: "2023",
title: "Grid 2.0 and real-time editing",
text: "Teams could finally work on the same page at once. Usage tripled within a year.",
},
{
year: "2025",
title: "Profitable and independent",
text: "No outside investors, no exit plan. Just a calm company that builds tools people pay for.",
},
{
year: "2026",
title: "Now: open-sourcing the core",
text: "The layout engine behind Grid is now free for anyone to use and improve.",
},
];
/** Nearest scrolling ancestor, or the window. Lets the piece work inside any scroll box. */
function scrollParent(el: HTMLElement | null): HTMLElement | Window {
for (let p = el?.parentElement; p; p = p.parentElement) {
const o = getComputedStyle(p).overflowY;
if (o === "auto" || o === "scroll") return p;
}
return window;
}
/**
* ScrollTimeline
* - Progress = how far the timeline's top has passed the middle of the viewport, divided by its height.
* - The line's scaleY is that progress; each item is "reached" when the line passes its dot.
*/
export function ScrollTimeline({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const list = useRef<HTMLOListElement>(null);
const [progress, setProgress] = useState(0);
const [reached, setReached] = useState<number>(-1);
useEffect(() => {
const el = list.current;
if (!el) return;
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
const raf = requestAnimationFrame(() => {
setProgress(1);
setReached(EVENTS.length);
});
return () => cancelAnimationFrame(raf);
}
const sp = scrollParent(el);
let raf = 0;
const update = () => {
raf = 0;
const box = el.getBoundingClientRect();
const viewTop = sp instanceof Window ? 0 : sp.getBoundingClientRect().top;
const viewH = sp instanceof Window ? innerHeight : sp.clientHeight;
const mid = viewTop + viewH * 0.6;
const p = Math.min(1, Math.max(0, (mid - box.top) / box.height));
setProgress(p);
const dots = el.querySelectorAll<HTMLElement>("[data-dot]");
let r = -1;
dots.forEach((d, i) => d.getBoundingClientRect().top < mid && (r = i));
setReached(r);
};
const onScroll = () => (raf ||= requestAnimationFrame(update));
onScroll();
sp.addEventListener("scroll", onScroll, { passive: true });
addEventListener("resize", onScroll);
return () => {
sp.removeEventListener("scroll", onScroll);
removeEventListener("resize", onScroll);
cancelAnimationFrame(raf);
};
}, []);
return (
<section className="gu-tl" data-theme={theme}>
<header>
<h2>Nine years, one idea.</h2>
<p>
Scroll to follow how a two-person studio became a calm, independent
software company.
</p>
</header>
<div className="gu-tl__wrap" style={{ "--p": progress } as CSSProperties}>
<span className="gu-tl__rail" aria-hidden="true" />
<ol ref={list} className="gu-tl__list">
{EVENTS.map((e, i) => (
<li
key={e.year}
data-side={i % 2 ? "right" : "left"}
data-on={i <= reached ? "" : undefined}
>
<span className="gu-tl__dot" data-dot aria-hidden="true" />
<div className="gu-tl__card">
<time>{e.year}</time>
<h3>{e.title}</h3>
<p>{e.text}</p>
</div>
</li>
))}
</ol>
</div>
</section>
);
}
```
### scroll-timeline.css
```css
/* ScrollTimeline: change these colors to match your brand. */
.gu-tl {
--bg: #f3eee3;
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.14);
--accent: #ff5a1f;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
container-type: inline-size;
padding: clamp(48px, 8%, 112px) clamp(16px, 4%, 48px) clamp(80px, 14%, 200px);
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-tl[data-theme="dark"] {
--bg: #0e0e10;
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.14);
}
.gu-tl header {
max-width: 640px;
margin: 0 auto clamp(40px, 7cqi, 96px);
text-align: center;
}
.gu-tl h2 {
margin: 0 0 14px;
font-size: clamp(2.4rem, 8cqi, 5.5rem);
font-weight: 900;
letter-spacing: -0.05em;
line-height: 0.9;
}
.gu-tl header p {
margin: 0;
color: var(--muted);
font-size: 1.05rem;
}
.gu-tl__wrap {
position: relative;
max-width: 1000px;
margin: 0 auto;
}
.gu-tl__list {
display: grid;
gap: clamp(28px, 5cqi, 64px);
margin: 0;
padding: 0;
list-style: none;
}
/* Gray rail + orange progress drawn with scaleY */
.gu-tl__rail,
.gu-tl__rail::after {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 3px;
margin-left: -1.5px;
border-radius: 3px;
background: var(--line);
}
.gu-tl__rail::after {
content: "";
left: 0;
margin: 0;
background: var(--accent);
transform: scaleY(var(--p));
transform-origin: top;
}
.gu-tl__list li {
position: relative;
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 64px;
}
.gu-tl__list li[data-side="left"] .gu-tl__card {
grid-column: 1;
text-align: right;
}
.gu-tl__list li[data-side="right"] .gu-tl__card {
grid-column: 2;
}
.gu-tl__dot {
position: absolute;
top: 28px;
left: 50%;
z-index: 1;
width: 22px;
height: 22px;
margin-left: -11px;
border: 3px solid var(--line);
border-radius: 50%;
background: var(--bg);
transition:
border-color 0.3s,
background-color 0.3s,
transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gu-tl__list li[data-on] .gu-tl__dot {
border-color: var(--accent);
background: var(--accent);
transform: scale(1.25);
}
.gu-tl__card {
padding: clamp(20px, 3cqi, 28px);
border: 1px solid var(--line);
border-radius: 24px;
background: var(--card);
opacity: 0.25;
transform: translateY(24px);
transition:
opacity 0.6s,
transform 0.8s var(--ease);
}
.gu-tl__list li[data-on] .gu-tl__card {
opacity: 1;
transform: none;
}
.gu-tl time {
color: var(--accent);
font-size: clamp(2rem, 5cqi, 3.2rem);
font-weight: 900;
letter-spacing: -0.05em;
line-height: 1;
}
.gu-tl[data-theme="light"] time {
color: var(
--text
); /* orange on Cream is only for display sizes; keep year Ink in light mode */
}
.gu-tl__list li[data-on] time {
color: var(--accent);
}
.gu-tl h3 {
margin: 8px 0 6px;
font-size: 1.2rem;
font-weight: 800;
letter-spacing: -0.02em;
}
.gu-tl__card p {
margin: 0;
color: var(--muted);
line-height: 1.55;
}
@container (max-width: 700px) {
.gu-tl__rail,
.gu-tl__dot {
left: 11px;
}
.gu-tl__list li {
grid-template-columns: 1fr;
padding-left: 44px;
}
.gu-tl__list li .gu-tl__card {
grid-column: 1 !important;
text-align: left !important;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-tl__card,
.gu-tl__dot {
transition: none;
}
}
```
You might also want
Next piece: Search with suggestionsChangelog timeline
Templates, intermediate
How it works, sticky scenes
Templates, intermediate
Minimal footer with progress
Templates, beginner