Skip to content
Molecules

Timeline

Events on a line that fill as you go.

Installation

  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/ and the colour tokens go into your CSS.

    $ pnpm dlx asta-ui@latest add timeline

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/timeline.json

  2. Or install the package

    Don’t want the file? Import from asta-ui/timeline and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui
    import { Timeline } from "asta-ui/timeline";
  3. Or copy it by hand

    Copy this file. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import { useEffect, useRef, type ReactNode } from "react";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    export type TimelineState = "done" | "active" | "pending";
    
    export interface TimelineItem {
      title: ReactNode;
      description?: ReactNode;
      /** A short time label, e.g. "09:41" or "Mon 12". */
      time?: ReactNode;
      /** Default `done`. `active` gets a soft blue pulse, `pending` a hollow dot and muted text. */
      state?: TimelineState;
    }
    
    export interface TimelineProps {
      items: TimelineItem[];
      /** Reveal the items one after another when the list scrolls into view. */
      animate?: boolean;
      /** Accessible name for the list. */
      label?: string;
      className?: string;
    }
    
    const KEYFRAMES = `@keyframes asta-timeline-in { from { opacity: 0; transform: translateY(8px) } }
    @keyframes asta-timeline-line { from { transform: scaleY(0) } }
    @keyframes asta-timeline-ping { 0% { opacity: .45; transform: scale(1) } 70%, 100% { opacity: 0; transform: scale(2.6) } }
    .asta-timeline[data-inview="false"] .asta-timeline-a { animation-play-state: paused }
    @media (prefers-reduced-motion: reduce) { .asta-timeline .asta-timeline-a, .asta-timeline .asta-timeline-ping { animation: none !important } }`;
    
    function Dot({ state }: { state: TimelineState }) {
      return (
        <span className="relative flex h-5 w-5 items-center justify-center">
          {state === "active" && <span aria-hidden className="asta-timeline-ping absolute h-2.5 w-2.5 rounded-full bg-brand animate-[asta-timeline-ping_2.4s_cubic-bezier(.16,1,.3,1)_infinite]" />}
          <span
            aria-hidden
            className={cx(
              "relative h-2.5 w-2.5 rounded-full",
              state === "done" && "bg-ink",
              state === "active" && "bg-brand shadow-[0_0_0_4px_color-mix(in_srgb,var(--color-brand)_16%,transparent)]",
              state === "pending" && "bg-paper shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_22%,transparent)]",
            )}
          />
        </span>
      );
    }
    
    /**
     * A vertical list of events with dots on a connector line. Items rise in one after another when the list
     * scrolls into view, the line between finished steps draws down, and the active step pulses softly.
     */
    export function Timeline({ items, animate = true, label = "Timeline", className }: TimelineProps) {
      const ref = useRef<HTMLOListElement>(null);
    
      // Hold the reveal until the list is on screen. Written to a data attribute, so no re-render.
      useEffect(() => {
        const el = ref.current;
        if (!el || !animate) return;
        const io = new IntersectionObserver(
          ([e]) => {
            if (!e.isIntersecting) return;
            el.dataset.inview = "true";
            io.disconnect();
          },
          { threshold: 0.2 },
        );
        io.observe(el);
        return () => io.disconnect();
      }, [animate]);
    
      return (
        <ol ref={ref} aria-label={label} data-inview={animate ? "false" : "true"} className={cx("asta-timeline flex flex-col", className)}>
          <style href="asta-timeline" precedence="asta">{KEYFRAMES}</style>
          {items.map((item, i) => {
            const state = item.state ?? "done";
            const last = i === items.length - 1;
            const next = items[i + 1]?.state ?? "done";
            // The line under a dot is "travelled" once the next step has started.
            const travelled = state === "done" && next !== "pending";
            return (
              <li
                key={i}
                aria-current={state === "active" ? "step" : undefined}
                className={cx("relative flex gap-3.5", animate && "asta-timeline-a animate-[asta-timeline-in_.6s_cubic-bezier(.16,1,.3,1)_both]")}
                style={animate ? { animationDelay: `${i * 90}ms` } : undefined}
              >
                <div className="relative flex w-5 shrink-0 flex-col items-center">
                  <Dot state={state} />
                  {!last && (
                    <span aria-hidden className="relative -mb-0.5 mt-0.5 w-px flex-1 overflow-hidden bg-[color-mix(in_srgb,var(--color-ink)_12%,transparent)]">
                      {travelled && (
                        <span
                          className={cx("absolute inset-0 origin-top bg-ink", animate && "asta-timeline-a animate-[asta-timeline-line_.7s_cubic-bezier(.16,1,.3,1)_both]")}
                          style={animate ? { animationDelay: `${i * 90 + 200}ms` } : undefined}
                        />
                      )}
                    </span>
                  )}
                </div>
                <div className={cx("min-w-0 flex-1", !last && "pb-6")}>
                  <div className="flex items-baseline justify-between gap-4">
                    <p className={cx("text-[14px] font-medium leading-5 tracking-[-0.01em]", state === "pending" ? "text-mute" : "text-ink")}>
                      {item.title}
                      <span className="sr-only">{state === "active" ? ", in progress" : state === "pending" ? ", not started" : ", done"}</span>
                    </p>
                    {item.time && <span className={cx("shrink-0 text-[12px] tabular-nums", state === "active" ? "text-brand" : "text-mute")}>{item.time}</span>}
                  </div>
                  {item.description && <div className="mt-0.5 text-[13px] leading-relaxed text-mute">{item.description}</div>}
                </div>
              </li>
            );
          })}
        </ol>
      );
    }
    
    export default Timeline;
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Timeline component to my project.
    
    Events on a line that fill as you go.
    It includes: done, active, pending, time, reveal on scroll.
    
    Install it:
    ```sh
    pnpm dlx asta-ui@latest add timeline --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/timeline.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { Timeline, type TimelineItem } from "@/components/astabyte/timeline";
    ```
    
    Usage example and props: https://ui.astabyte.com/timeline
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
  5. Or use plain HTML + CSS

    Not on React? Use it from Django, Rails, Laravel, Go html/template, htmx or a static page. Load asta.css and asta.js once (the head.html tab), then paste the markup. The ui.astabyte.com/cdn link is temporary: pin a version from jsDelivr for production. More in HTML + CSS.

    <!-- asta.js starts the enter animation when the list scrolls into view (data-inview). Without it, set data-inview="true". -->
    <div style="max-width:420px"><ol class="asta-timeline asta-timeline-root" data-asta-timeline data-inview="false" aria-label="Order history">
    <li class="asta-timeline-item asta-timeline-a asta-timeline-enter" style="animation-delay:0ms"><div class="asta-timeline-rail"><span class="asta-timeline-marker"><span aria-hidden="true" class="asta-timeline-dot"></span></span>
    <span aria-hidden="true" class="asta-timeline-track"><span class="asta-timeline-progress asta-timeline-a asta-timeline-draw" style="animation-delay:200ms"></span></span>
    </div><div class="asta-timeline-body"><div class="asta-timeline-head"><p class="asta-timeline-title">Order placed<span class="asta-sr-only">, done</span></p><span class="asta-timeline-time">09:41</span></div><div class="asta-timeline-desc">Astabyte Pro, yearly plan</div></div></li>
    <li class="asta-timeline-item asta-timeline-a asta-timeline-enter" style="animation-delay:90ms"><div class="asta-timeline-rail"><span class="asta-timeline-marker"><span aria-hidden="true" class="asta-timeline-dot"></span></span>
    <span aria-hidden="true" class="asta-timeline-track"><span class="asta-timeline-progress asta-timeline-a asta-timeline-draw" style="animation-delay:290ms"></span></span>
    </div><div class="asta-timeline-body"><div class="asta-timeline-head"><p class="asta-timeline-title">Payment confirmed<span class="asta-sr-only">, done</span></p><span class="asta-timeline-time">09:42</span></div><div class="asta-timeline-desc">Visa ending 4242</div></div></li>
    <li class="asta-timeline-item asta-timeline-a asta-timeline-enter asta-timeline-active" aria-current="step" style="animation-delay:180ms"><div class="asta-timeline-rail"><span class="asta-timeline-marker"><span aria-hidden="true" class="asta-timeline-ping asta-timeline-pulse"></span><span aria-hidden="true" class="asta-timeline-dot"></span></span>
    <span aria-hidden="true" class="asta-timeline-track"></span>
    </div><div class="asta-timeline-body"><div class="asta-timeline-head"><p class="asta-timeline-title">Workspace ready<span class="asta-sr-only">, in progress</span></p><span class="asta-timeline-time">09:44</span></div><div class="asta-timeline-desc">Invites sent to 4 teammates</div></div></li>
    <li class="asta-timeline-item asta-timeline-a asta-timeline-enter asta-timeline-pending" style="animation-delay:270ms"><div class="asta-timeline-rail"><span class="asta-timeline-marker"><span aria-hidden="true" class="asta-timeline-dot"></span></span>
    </div><div class="asta-timeline-body"><div class="asta-timeline-head"><p class="asta-timeline-title">First project<span class="asta-sr-only">, not started</span></p></div><div class="asta-timeline-desc">Create one to finish setup</div></div></li>
    </ol></div>

Usage

The demo above, as code.

"use client";

import { Timeline, type TimelineItem } from "@/components/astabyte/timeline";

const EVENTS: TimelineItem[] = [
  { title: "Order placed", description: "Linen overshirt and canvas tote", time: "Mon 09:41" },
  { title: "Packed", description: "Lisbon warehouse", time: "Mon 16:20" },
  { title: "On the way", description: "Arriving between 14:00 and 16:00", time: "Today", state: "active" },
  { title: "Delivered", description: "Leave at the front door", state: "pending" },
];

export default function TimelineDemo() {
  return (
    <div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
      <div className="w-full max-w-sm rounded-xl bg-paper-2 p-5">
        <div className="mb-5 flex items-baseline justify-between gap-4">
          <p className="text-[15px] font-medium tracking-[-0.01em] text-ink">Order #10482</p>
          <span className="text-[12px] text-mute">Tracking 4R7-22X</span>
        </div>
        <Timeline items={EVENTS} label="Delivery progress" />
      </div>
    </div>
  );
}