Timeline
A scroll-animated vertical timeline for React and Tailwind CSS, perfect for changelogs, roadmaps and company history. A progress line traces down the rail as you scroll, each dot lights up as the line reaches it, entries fade and slide in, and on wide layouts the dates stick beside their entry. Works on the page or inside any scroll container.
- Scroll-linked progress
- Sticky dates
- Scroll containers
- Container queries
- SEO-friendly
- prefers-reduced-motion
"use client";
import * as React from "react";
import { Timeline, TimelineItem } from "@/components/dusk/timeline/timeline";
const releases = [
{
version: "v3.0",
date: "Nov 2026",
dateTime: "2026-11",
title: "Component library 3.0",
body: "A flat component list, 20 new showcase components and a rebuilt docs site with live previews.",
tags: ["Major", "Docs"],
},
{
version: "v2.6",
date: "Sep 2026",
dateTime: "2026-09",
title: "Scroll-linked everything",
body: "Scroll Reveal Text, Blur Panel and a new container prop so effects work inside any scroll area.",
tags: ["Feature"],
},
{
version: "v2.4",
date: "Jul 2026",
dateTime: "2026-07",
title: "Reduced motion audit",
body: "Every component now checks prefers-reduced-motion and falls back to a calm, static state.",
tags: ["Accessibility"],
},
{
version: "v2.0",
date: "Apr 2026",
dateTime: "2026-04",
title: "Motion 12 and React 19",
body: "Moved to the motion package, layout animations everywhere and no more hydration warnings.",
tags: ["Major"],
},
{
version: "v1.0",
date: "Jan 2026",
dateTime: "2026-01",
title: "First public release",
body: "Buttons, cards and text effects built on shadcn/ui, with a neon mint dark theme.",
tags: ["Launch"],
},
];
export default function TimelineDemo() {
const scroller = React.useRef<HTMLDivElement>(null);
return (
<div
ref={scroller}
tabIndex={0}
aria-label="Changelog, scrollable"
className="relative h-[26rem] w-full max-w-2xl overflow-y-auto rounded-xl border border-white/10 bg-black/30 px-5 outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [scrollbar-width:thin] sm:px-8"
>
<h3 className="mt-6 mb-6 text-lg font-semibold tracking-tight">Changelog</h3>
<Timeline container={scroller} anchor={0.55} stickyTop="1.5rem">
{releases.map((r) => (
<TimelineItem key={r.version} date={r.date} dateTime={r.dateTime} title={`${r.version} · ${r.title}`}>
<p>{r.body}</p>
<ul className="mt-3 flex flex-wrap gap-1.5" aria-label="Tags">
{r.tags.map((tag) => (
<li key={tag} className="rounded-full border border-white/10 px-2 py-0.5 text-xs text-white/55">
{tag}
</li>
))}
</ul>
{/* Placeholder for screenshots, release notes… */}
<div aria-hidden className="mt-4 h-24 rounded-lg border border-white/5 bg-white/[0.02]" />
</TimelineItem>
))}
</Timeline>
<div className="h-48" />
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/timeline.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/timeline/timeline.tsx.timeline.tsx "use client"; import * as React from "react"; import { animate, motion, useInView, useMotionValue, useReducedMotion, useScroll, useSpring, useTransform, type UseInViewOptions, } from "motion/react"; import { cn } from "@/lib/utils"; type TimelineContextValue = { container?: React.RefObject<HTMLElement | null>; anchor: number; reduceMotion: boolean; }; const TimelineContext = React.createContext<TimelineContextValue>({ anchor: 0.5, reduceMotion: false }); export interface TimelineProps extends Omit<React.HTMLAttributes<HTMLOListElement>, "children"> { /** `TimelineItem`s, in order. */ children: React.ReactNode; /** The scrolling element, if the timeline lives in a scroll container instead of the page. */ container?: React.RefObject<HTMLElement | null>; /** * Where the tip of the progress line sits, as a fraction of the viewport (or * container) height. Items light up as they cross this line. Default: the middle. */ anchor?: number; /** Distance from the top of the viewport (or container) where dates stick on wide layouts. Any CSS length. */ stickyTop?: string; /** Classes for the progress line (the bright part of the rail). */ lineClassName?: string; } /** * A vertical timeline or changelog whose rail fills as you scroll. * * The rail's fill is a `scaleY` transform driven by `useScroll` on the list * itself, so the tip always sits on the `anchor` line of the viewport and * scrolling never re-renders React. Works on the page or in any scroll * container (`container`). Wide layouts (container width ≥ 36rem) put the * date in its own sticky column; narrow ones stack it above the title. * * Everything is fully visible on the server, for no-JS visitors and under * reduced motion; entries below the fold fade in as they arrive. */ export function Timeline({ children, container, anchor = 0.5, stickyTop = "5rem", lineClassName, className, style, ...props }: TimelineProps) { const ref = React.useRef<HTMLOListElement>(null); const reduceMotion = useReducedMotion() ?? false; const a = Math.min(1, Math.max(0, anchor)); const { scrollYProgress } = useScroll({ target: ref, container, offset: [`start ${a}`, `end ${a}`], }); const smooth = useSpring(scrollYProgress, { stiffness: 260, damping: 40, restDelta: 0.001 }); // 1 (full line) on the server and under reduced motion; follows scroll once armed. const armed = useMotionValue(0); const scaleY = useTransform([smooth, armed], ([p, on]: number[]) => (on ? p : 1)); React.useLayoutEffect(() => { armed.set(reduceMotion ? 0 : 1); }, [reduceMotion, armed]); const context = React.useMemo(() => ({ container, anchor: a, reduceMotion }), [container, a, reduceMotion]); return ( <TimelineContext.Provider value={context}> <div className="@container"> <ol ref={ref} data-slot="timeline" className={cn( "relative [--tl-date:8.5rem] [--tl-dot:1.75rem] [--tl-gap:1.25rem] @xl:[--tl-gap:1.5rem]", className )} style={{ "--tl-sticky": stickyTop, ...style } as React.CSSProperties} {...props} > {/* Rail: a dim track with the scroll-driven fill on top. */} <span aria-hidden className="pointer-events-none absolute inset-y-[calc(var(--tl-dot)/2)] left-[calc(var(--tl-dot)/2)] w-px -translate-x-1/2 bg-white/10 @xl:left-[calc(var(--tl-date)+var(--tl-gap)+var(--tl-dot)/2)]" > <motion.span className={cn( "absolute inset-0 origin-top bg-primary", lineClassName )} style={{ scaleY }} /> </span> {children} </ol> </div> </TimelineContext.Provider> ); } /** Nearest ancestor that scrolls vertically. */ function scrollParent(el: HTMLElement) { for (let node = el.parentElement; node; node = node.parentElement) { if (/(auto|scroll|overlay)/.test(getComputedStyle(node).overflowY)) return node; } return null; } export interface TimelineItemProps extends Omit<React.HTMLAttributes<HTMLLIElement>, "title"> { /** Date label, e.g. `"Mar 2026"` or `"v2.4.0"`. */ date: React.ReactNode; /** Machine-readable date for the `<time>` element, e.g. `"2026-03"`. */ dateTime?: string; /** Entry heading. */ title: React.ReactNode; /** Heading element for the title. */ titleAs?: "h2" | "h3" | "h4"; /** Icon inside the rail dot. Defaults to a small dot. */ icon?: React.ReactNode; } /** * One entry: a sticky date (wide layouts), a dot on the rail that lights up * when the progress line reaches it, and the content, which fades and slides * in the first time it scrolls into view. */ export function TimelineItem({ date, dateTime, title, titleAs: Title = "h3", icon, className, children, ...props }: TimelineItemProps) { const { container, anchor, reduceMotion } = React.useContext(TimelineContext); const ref = React.useRef<HTMLLIElement>(null); const dotRef = React.useRef<HTMLSpanElement>(null); // Lit while the dot is above the anchor line. const reached = useInView(dotRef, { root: container, margin: `9999px 0px -${Math.round((1 - anchor) * 100)}% 0px` as UseInViewOptions["margin"], }); // First time the entry comes into view. const entered = useInView(ref, { root: container, once: true, margin: "0px 0px -10% 0px" }); const opacity = useMotionValue(1); const y = useMotionValue(0); const hidden = React.useRef(false); // Before the first paint, hide only entries that are still below the fold, // so nothing that's already visible flashes. React.useLayoutEffect(() => { const el = ref.current; if (!el || reduceMotion) return; // On mount an ancestor container's ref isn't attached yet, so fall back to the DOM. const root = container ? (container.current ?? scrollParent(el)) : null; const fold = root ? (() => { const r = root.getBoundingClientRect(); return r.top + r.height * 0.95; })() : window.innerHeight * 0.95; if (el.getBoundingClientRect().top > fold) { hidden.current = true; opacity.set(0); y.set(8); } }, [container, reduceMotion, opacity, y]); React.useEffect(() => { if (!entered || !hidden.current) return; hidden.current = false; const a = animate(opacity, 1, { duration: 0.3, ease: "easeOut" }); const b = animate(y, 0, { duration: 0.3, ease: "easeOut" }); return () => { a.stop(); b.stop(); }; }, [entered, opacity, y]); return ( <li ref={ref} data-slot="timeline-item" data-reached={reached || undefined} className={cn( "group/tl relative grid grid-cols-[var(--tl-dot)_1fr] gap-x-(--tl-gap) pb-10 last:pb-0", "@xl:grid-cols-[var(--tl-date)_var(--tl-dot)_1fr]", className )} {...props} > {/* Date: above the title when narrow, its own sticky column when wide. */} <div className="col-start-2 row-start-1 @xl:col-start-1 @xl:row-span-2 @xl:text-right"> <motion.time dateTime={dateTime} style={{ opacity }} className="mb-1 block text-xs font-medium text-white/50 transition-colors duration-300 group-data-reached/tl:text-white/80 @xl:sticky @xl:top-(--tl-sticky) @xl:mb-0 @xl:pt-1 @xl:text-sm" > {date} </motion.time> </div> {/* Dot on the rail. */} <div className="col-start-1 row-span-2 row-start-1 @xl:col-start-2"> <span ref={dotRef} aria-hidden className={cn( "relative z-10 flex size-(--tl-dot) items-center justify-center rounded-full border border-white/15 bg-background text-white/55", "transition-[color,border-color] duration-300 [&_svg]:size-3.5", "group-data-reached/tl:border-primary group-data-reached/tl:text-primary" )} > {icon ?? ( <span className="size-2 rounded-full bg-current" /> )} </span> </div> <motion.div style={{ opacity, y }} className="col-start-2 row-start-2 min-w-0 @xl:col-start-3 @xl:row-start-1 @xl:row-span-2"> <Title className="text-base font-semibold tracking-tight text-white @xl:pt-0.5">{title}</Title> {children && <div className="mt-2 text-sm leading-relaxed text-white/60">{children}</div>} </motion.div> </li> ); }
Usage
import { Timeline, TimelineItem } from "@/components/dusk/timeline/timeline"
export function Changelog() {
return (
<Timeline>
<TimelineItem date="Nov 2026" dateTime="2026-11" title="v3.0 · Component library 3.0">
A flat component list and 20 new components.
</TimelineItem>
<TimelineItem date="Sep 2026" dateTime="2026-09" title="v2.6 · Scroll-linked everything">
New container prop for scroll areas.
</TimelineItem>
</Timeline>
)
}Examples
Roadmap with icons
Pass an icon for each dot (lineClassName restyles the line if you need to). anchor moves the line's tip (here 70% down the scroll area). In a narrow container the dates stack above each title; the layout switches with container queries, not the viewport.
"use client";
import * as React from "react";
import { Flag, Lightbulb, PenTool, Rocket, TestTube } from "lucide-react";
import { Timeline, TimelineItem } from "@/components/dusk/timeline/timeline";
const steps = [
{ icon: Lightbulb, date: "Week 1", title: "Discovery", body: "Interview ten customers and map the jobs they hire the product for." },
{ icon: PenTool, date: "Week 2–3", title: "Design", body: "Wireframes, a clickable prototype and a round of hallway tests." },
{ icon: TestTube, date: "Week 4–6", title: "Build & test", body: "Ship behind a flag to 5% of users and watch the metrics." },
{ icon: Rocket, date: "Week 7", title: "Launch", body: "Flip the flag, publish the changelog and post it in the changelog." },
{ icon: Flag, date: "Week 8", title: "Review", body: "Measure against the goals we set in week one and decide what's next." },
];
export default function TimelineRoadmapDemo() {
const scroller = React.useRef<HTMLDivElement>(null);
return (
<div
ref={scroller}
tabIndex={0}
aria-label="Roadmap, scrollable"
className="relative h-96 w-full max-w-md overflow-y-auto rounded-xl border border-white/10 bg-black/30 px-6 outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [scrollbar-width:thin]"
>
<div className="h-24" />
<Timeline container={scroller} anchor={0.7}>
{steps.map(({ icon: Icon, date, title, body }) => (
<TimelineItem key={title} date={date} title={title} icon={<Icon />}>
{body}
</TimelineItem>
))}
</Timeline>
<div className="h-56" />
</div>
);
}API Reference
Timeline renders an ol and accepts its attributes; TimelineItem renders an li.
| Prop | Type | Default | Description |
|---|---|---|---|
| container | RefObject<HTMLElement | null> | — | Timeline: the scrolling element, when it lives in a scroll container. |
| anchor | number | 0.5 | Timeline: where the line's tip sits, as a fraction of the viewport / container height. Dots light up as they cross it. |
| stickyTop | string | "5rem" | Timeline: CSS length from the top where dates stick on wide layouts. Match your sticky header. |
| lineClassName | string | — | Timeline: classes for the progress line. |
| date | ReactNode | — | TimelineItem: date label, rendered in a <time>. |
| dateTime | string | — | TimelineItem: machine-readable date for the <time> element. |
| title | ReactNode | — | TimelineItem: entry heading. |
| titleAs | "h2" | "h3" | "h4" | "h3" | TimelineItem: heading element. |
| icon | ReactNode | — | TimelineItem: icon inside the rail dot. Defaults to a small dot. |
| children | ReactNode | — | TimelineItem: entry body. |
Accessibility
- It is an ordered list of entries, each with a heading and a <time> element (use dateTime for a machine-readable date), so it reads well in screen readers and search results.
- Each date is rendered once; the wide and narrow layouts only move it with CSS grid.
- The server, no-JS visitors and the first paint show every entry. Only entries still below the fold are hidden before the first paint and then fade in.
- The rail and dots are aria-hidden decoration. The progress line is a scaleY transform driven by scroll Motion values, so scrolling never re-renders React.
- With prefers-reduced-motion the line is drawn in full and entries are simply visible; dots still change color as you scroll.