Marquee
Content that scrolls forever at a steady speed, sideways or up a column, with an optional glide to a stop on hover.
$npx shadcn@latest add https://framebrick.co/r/marquee.jsonFrom the Nitip template, see it in context.
import { Marquee } from "@/components/ui/marquee";
const clients = ["Northwind", "Lumen", "Arcadia", "Kestrel", "Halden", "Oakmere"];
export default function MarqueeDemo() {
return (
<Marquee pauseOnHover fade gap={48} className="w-full">
{clients.map((name) => (
<span key={name} className="text-2xl font-semibold tracking-tight text-muted-foreground">
{name}
</span>
))}
</Marquee>
);
}Examples
Vertical
A column in a small window: the lines roll up, one after another, with faded edges.
import { Marquee } from "@/components/ui/marquee";
const specialities = ["Brand photography", "Editorial design", "Creative direction", "Web design"];
/* A column in a window two lines tall: the lines roll up, and the edges fade. */
export default function MarqueeVerticalDemo() {
return (
<div className="flex flex-col items-center gap-1 text-xl font-semibold tracking-tight">
<span className="text-muted-foreground">I specialize in</span>
<Marquee direction="up" speed={12} gap={8} fade className="h-16 w-56">
{specialities.map((name) => (
<span key={name} className="block h-8 text-center leading-8 whitespace-nowrap">
{name}
</span>
))}
</Marquee>
</div>
);
}<Marquee direction="up" speed={12} gap={8} fade className="h-16 w-52">
{specialities.map((name) => (
<span key={name} className="block h-8 leading-8 whitespace-nowrap">{name}</span>
))}
</Marquee>On hover
Two photo columns stand still and roll, one up and one down, only while the pointer is on the card.
Portrait sessions
Hover the card and the photos roll.
















import { Marquee } from "@/components/ui/marquee";
const photos = ["showreel-desk", "showreel-meeting", "showreel-screen", "showreel-studio"];
/* Marai Neesu's service card: the photo columns stand still and roll, one up and one down, while the pointer is on the card. */
export default function MarqueeHoverDemo() {
return (
<div className="group flex h-40 w-full max-w-xs overflow-hidden rounded-lg border bg-card">
<div className="flex flex-1 flex-col justify-between p-4">
<div>
<p className="text-sm font-semibold">Portrait sessions</p>
<p className="mt-1 text-xs text-muted-foreground">Hover the card and the photos roll.</p>
</div>
<span className="w-fit rounded-full border px-2.5 py-0.5 text-xs text-muted-foreground">From $900</span>
</div>
<div className="flex gap-2 px-3 opacity-60 transition-opacity duration-300 group-hover:opacity-80">
{(["up", "down"] as const).map((direction) => (
<Marquee key={direction} direction={direction} run="hover" hoverTarget=".group" speed={14} gap={8} className="h-full w-14">
{(direction === "up" ? photos : [...photos].reverse()).map((photo) => (
<img key={photo} src={`/demo/${photo}.webp`} alt="" className="h-20 w-14 rounded-md object-cover" />
))}
</Marquee>
))}
</div>
</div>
);
}<Marquee direction="up" run="hover" hoverTarget=".group" speed={14} gap={8} className="h-full w-14">
{photos.map((photo) => <img key={photo} src={photo} alt="" className="h-20 w-14 rounded-md object-cover" />)}
</Marquee>Installation
$ npx shadcn@latest add https://framebrick.co/r/marquee.json1. Install the dependencies.
npm install motion clsx tailwind-merge2. Add
cn()tolib/utils.ts(skip if shadcn already created it).import { clsx, type ClassValue } from "clsx"; import { extendTailwindMerge } from "tailwind-merge"; /* tailwind-merge must know the site's type scale (globals.css) is a font size, not a text color — otherwise cn("text-h6 text-muted-foreground") drops text-h6. */ const twMerge = extendTailwindMerge({ extend: { classGroups: { "font-size": [{ text: ["display", "h1", "h2", "h3", "h4", "h5", "h6"] }] } }, }); export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); }3. Copy the component into
components/ui/marquee.tsx."use client"; import * as React from "react"; import { animate, useReducedMotion } from "motion/react"; import { cn } from "@/lib/utils"; /* * Marquee — content that scrolls forever at a steady speed (from the Nitip "Ticker"): sideways, or up and down a * column (from the Tustel Ticker, which rolls its specialities up a one-line window at 5 px/s). * Speed is in pixels per second, so it stays the same whatever the content size. * Optional: glide to a stop on hover, fade the edges. With reduced motion it stands still. * "up" and "down" run a column, so the marquee needs a height of its own (`className="h-6"`); the sideways ones take * the width of their container. * `run="hover"` (from the Marai Neesu service card, whose photo columns roll only while the pointer is on the card) turns * it round: it stands at its start, runs while the pointer or the keyboard focus is on it, and when they leave it stops * and jumps back to the start at once. "On it" is the marquee itself, or with `hoverTarget` the nearest ancestor that * matches that selector (`hoverTarget=".group"`: the whole card wakes the columns, not just the strip of photos). */ export type MarqueeProps = { children: React.ReactNode; /** Pixels per second. */ speed?: number; /** "left" and "right" run a row; "up" and "down" run a column and need a height. */ direction?: "left" | "right" | "up" | "down"; /** Space between items and between copies, in px. */ gap?: number; /** Copies of the children in each half of the loop; raise it when the content is smaller than the container. */ repeat?: number; /** Slow to a stop while hovered. Not with `run="hover"`. */ pauseOnHover?: boolean; /** "always" runs forever; "hover" stands at its start, runs while the pointer or focus is on it, then jumps back. */ run?: "always" | "hover"; /** With run="hover": a selector for the nearest ancestor whose hover and focus wake it (".group", "[data-card]"); itself when left out. */ hoverTarget?: string; /** Fade both edges into the background. */ fade?: boolean; className?: string; }; export function Marquee({ children, speed = 40, direction = "left", gap = 32, repeat = 2, pauseOnHover = false, run = "always", hoverTarget, fade = false, className, }: MarqueeProps) { const root = React.useRef<HTMLDivElement>(null); const track = React.useRef<HTMLDivElement>(null); const loop = React.useRef<Animation | null>(null); const reduce = useReducedMotion(); const vertical = direction === "up" || direction === "down"; /* With run="hover": whether the pointer or the focus is on the marquee now. */ const awake = React.useRef(false); const onHover = run === "hover"; React.useEffect(() => { const el = track.current; if (!el || reduce) return; /* (Re)start on every size change, keeping the current position so a resize doesn't jump. */ function start() { if (!el) return; const duration = ((vertical ? el.scrollHeight : el.scrollWidth) / 2 / speed) * 1000; const previous = loop.current; const previousDuration = Number(previous?.effect?.getTiming().duration) || 1; const progress = previous ? (Number(previous.currentTime ?? 0) % previousDuration) / previousDuration : 0; /* On hover it waits at its start (rate 0) until something is over it. */ const rate = onHover ? (awake.current ? 1 : 0) : (previous?.playbackRate ?? 1); previous?.cancel(); const [from, to] = direction === "left" || direction === "up" ? ["0%", "-50%"] : ["-50%", "0%"]; const axis = vertical ? "Y" : "X"; const next = el.animate([{ transform: `translate${axis}(${from})` }, { transform: `translate${axis}(${to})` }], { duration, iterations: Infinity, easing: "linear", }); next.currentTime = progress * duration; next.playbackRate = rate; loop.current = next; } const observer = new ResizeObserver(start); observer.observe(el); return () => { observer.disconnect(); loop.current?.cancel(); loop.current = null; }; }, [speed, direction, vertical, reduce, onHover]); /* run="hover": go while the pointer or the focus is on the marquee (or on the ancestor hoverTarget names); when they leave, stop and jump back to the start. Native listeners, because the ancestor is not ours to put handlers on. */ React.useEffect(() => { if (!onHover) return; const element = root.current; const host = (hoverTarget ? element?.closest(hoverTarget) : element) ?? element; if (!host) return; const wake = (on: boolean) => { awake.current = on; const current = loop.current; if (!current) return; current.playbackRate = on ? 1 : 0; if (!on) current.currentTime = 0; }; const enter = () => wake(true); const leave = () => wake(false); const focusOut = (event: Event) => { if (!host.contains((event as FocusEvent).relatedTarget as Node | null)) wake(false); }; host.addEventListener("pointerenter", enter); host.addEventListener("pointerleave", leave); host.addEventListener("focusin", enter); host.addEventListener("focusout", focusOut); return () => { host.removeEventListener("pointerenter", enter); host.removeEventListener("pointerleave", leave); host.removeEventListener("focusin", enter); host.removeEventListener("focusout", focusOut); }; }, [onHover, hoverTarget]); const brake = React.useRef<ReturnType<typeof animate> | null>(null); function glide(to: number) { const current = loop.current; if (!pauseOnHover || onHover || !current) return; brake.current?.stop(); brake.current = animate(current.playbackRate, to, { duration: 0.5, ease: "easeOut", onUpdate: (rate) => { current.playbackRate = rate; }, }); } const group = ( <div className={cn("flex shrink-0", vertical ? "flex-col" : "items-center")} style={vertical ? { gap, paddingBottom: gap } : { gap, paddingRight: gap }} > {Array.from({ length: repeat }, (_, i) => ( <React.Fragment key={i}>{children}</React.Fragment> ))} </div> ); return ( <div ref={root} className={cn("overflow-hidden", className)} onPointerEnter={() => glide(0)} onPointerLeave={() => glide(1)} style={ fade ? { maskImage: `linear-gradient(${vertical ? "to bottom" : "to right"}, transparent, black 10%, black 90%, transparent)`, WebkitMaskImage: `linear-gradient(${vertical ? "to bottom" : "to right"}, transparent, black 10%, black 90%, transparent)`, } : undefined } > <div ref={track} className={cn("flex will-change-transform", vertical ? "flex-col" : "w-max")}> {group} <div aria-hidden className="contents" inert> {group} </div> </div> </div> ); }
Usage
import { Marquee } from "@/components/ui/marquee";
<Marquee speed={40} pauseOnHover fade>
{logos.map((logo) => <img key={logo.src} src={logo.src} alt={logo.name} className="h-8" />)}
</Marquee>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| speed | number | 40 | Pixels per second — the same whatever the content size. |
| direction | "left" | "right" | "up" | "down" | "left" | "left" and "right" run a row; "up" and "down" run a column and need a height of their own (className="h-6"). |
| gap | number | 32 | Space between items, in px. |
| repeat | number | 2 | Copies of the children per loop half; raise it for short content. |
| pauseOnHover | boolean | false | Glide to a stop while hovered, then speed back up. Not with run="hover". |
| run | "always" | "hover" | "always" | "hover" stands at its start and runs only while the pointer or the keyboard focus is on it, then stops and jumps back to the start at once (Marai Neesu's service photos). |
| hoverTarget | string | — | With run="hover": a selector for the nearest ancestor whose hover and focus wake it (".group", "[data-card]"); the marquee itself when left out. |
| fade | boolean | false | Fade both edges into the background. |
- With reduced motion enabled it stands still.
- The second copy is hidden from screen readers and inert.
- run="hover" is Marai Neesu's service card: two photo columns, one rolling up and one down at 5 px/s there, that stand still until the pointer is on the card and jump back to the start when it leaves. Keyboard focus inside starts it too. hoverTarget=".group" makes the whole card the trigger; without it only the strip of photos wakes them.
- "up" and "down" are Tustel's vertical ticker (5 px/s, its specialities rolling up a one-line window): the track is a column, the loop moves it on the Y axis, and the fade mask runs top to bottom. A column needs a height; a row takes the width of its container.
AI prompt
Paste into v0, Lovable, Bolt or Claude to rebuild this component in your own project.
Create a React + Tailwind CSS component called Marquee (infinite ticker, sideways or up and down), using the Web Animations API. - Outer div overflow-hidden; inner track w-max flex with two identical groups of the children (second copy aria-hidden and inert). Each group repeats the children N times with a gap and padding-right equal to the gap, so the loop is seamless. - Animate the track translateX 0% → -50% (or reverse for direction right), linear, infinite. Duration = (track width / 2) / speed in px per second. Re-create the animation on resize (ResizeObserver), keeping the current progress so it doesn't jump. - direction "up" and "down" run a column instead: the track is flex-col (not w-max), each group is flex-col with the gap as padding-bottom, the animation is translateY 0% → -50% (up) or -50% → 0% (down), and the duration uses the track's height. The caller gives the marquee a height. - pauseOnHover: tween the animation's playbackRate to 0 over 0.5s ease-out on pointer enter, back to 1 on leave. - run "hover": create the animation paused (playbackRate 0) at its start; pointerenter or focusin on the host sets playbackRate 1; pointerleave, or focusout to somewhere outside the host, sets it back to 0 and currentTime to 0 (a jump back to the start). The host is the marquee itself, or with a hoverTarget selector its nearest ancestor that matches (element.closest), so a whole card can wake it. - fade: mask-image linear-gradient (to right, or to bottom for a column) transparent → black 10% → black 90% → transparent. - Respect prefers-reduced-motion: no animation.











