Marquee
An infinite scrolling marquee for React and Tailwind CSS: a seamless, transform-only loop for logo clouds, testimonials and tags, in any direction, horizontal or vertical. It measures its content, clones just enough copies to fill the space, eases to a stop on hover and becomes a static scrollable row for reduced-motion users.
- Seamless loop
- Horizontal & vertical
- Pause on hover & focus
- Fade edges
- No re-renders
- prefers-reduced-motion
Used by product teams at
import { Atom, Boxes, Cloud, Hexagon, InfinityIcon, Orbit, Rocket, Triangle, Waves, Zap } from "lucide-react";
import { Marquee } from "@/components/dusk/marquee/marquee";
const brands = [
{ name: "Nebula", icon: Orbit },
{ name: "Quanta", icon: Atom },
{ name: "Lumen", icon: Zap },
{ name: "Vertex", icon: Triangle },
{ name: "Stratus", icon: Cloud },
{ name: "Hexa", icon: Hexagon },
{ name: "Tidal", icon: Waves },
{ name: "Cubic", icon: Boxes },
{ name: "Ascent", icon: Rocket },
{ name: "Loopwise", icon: InfinityIcon },
];
function Logo({ name, icon: Icon }: (typeof brands)[number]) {
return (
<div className="flex items-center gap-2 px-4 text-white/50 transition-colors hover:text-white">
<Icon aria-hidden className="size-5" />
<span className="text-lg font-semibold tracking-tight">{name}</span>
</div>
);
}
export default function MarqueeDemo() {
return (
<section aria-label="Trusted by" className="w-full max-w-2xl space-y-4">
<p className="text-center text-sm text-muted-foreground">Used by product teams at</p>
<Marquee speed={36} gap={24}>
{brands.map((brand) => (
<Logo key={brand.name} {...brand} />
))}
</Marquee>
<Marquee direction="right" speed={28} gap={24}>
{[...brands].reverse().map((brand) => (
<Logo key={brand.name} {...brand} />
))}
</Marquee>
</section>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/marquee.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/marquee/marquee.tsx.marquee.tsx "use client"; import * as React from "react"; import { animate, motion, useAnimationFrame, useInView, useMotionValue, useReducedMotion, useTransform, } from "motion/react"; import { cn } from "@/lib/utils"; type MarqueeDirection = "left" | "right" | "up" | "down"; export interface MarqueeProps extends React.HTMLAttributes<HTMLDivElement> { /** The items to scroll. Rendered once, then cloned (aria-hidden) as many times as needed to fill the loop. */ children: React.ReactNode; /** Which way the content travels. `up` / `down` make a vertical marquee: give it a height. */ direction?: MarqueeDirection; /** Speed in pixels per second. */ speed?: number; /** Space between items (and between the last item and the next copy), in px. */ gap?: number; /** Ease to a stop while the pointer is over the marquee or something inside it has focus. */ pauseOnHover?: boolean; /** Stop the marquee, e.g. from your own pause button. */ paused?: boolean; /** Fade the leading and trailing edges with a mask. `true` = 64px, or a size in px. */ fade?: boolean | number; /** Classes for each copy of the content (the flex row/column that holds the items). */ groupClassName?: string; } const subscribe = () => () => {}; /** `false` on the server and during hydration, `true` afterwards. */ function useHydrated() { return React.useSyncExternalStore( subscribe, () => true, () => false ); } /** * An infinitely scrolling row (or column) for logos, testimonials and tags. * * The content is measured and cloned just enough times to cover the viewport * plus one copy, then the track is moved with a single transform that wraps * by exactly one copy's length, so the loop is seamless at any width and * never re-renders React while it runs. The clones are `aria-hidden` and * `inert`, so screen readers and the Tab key only meet the original items. * * It eases to a stop on hover and while focus is inside, pauses off-screen, * and under reduced motion becomes a static, scrollable row. */ export function Marquee({ children, direction = "left", speed = 40, gap = 16, pauseOnHover = true, paused = false, fade = true, groupClassName, className, style, onPointerEnter, onPointerLeave, onFocus, onBlur, ...props }: MarqueeProps) { const vertical = direction === "up" || direction === "down"; const forward = direction === "left" || direction === "up"; const hydrated = useHydrated(); const reduceMotion = (useReducedMotion() ?? false) && hydrated; const rootRef = React.useRef<HTMLDivElement>(null); const groupRef = React.useRef<HTMLDivElement>(null); const inView = useInView(rootRef, { margin: "100px" }); // Length of one copy (content + trailing gap), in px. const size = React.useRef(0); const [copies, setCopies] = React.useState(2); React.useLayoutEffect(() => { const root = rootRef.current; const group = groupRef.current; if (!root || !group || reduceMotion) return; const measure = () => { const groupLength = vertical ? group.offsetHeight : group.offsetWidth; const rootLength = vertical ? root.clientHeight : root.clientWidth; size.current = groupLength; if (groupLength > 0) setCopies(Math.max(2, Math.ceil(rootLength / groupLength) + 1)); }; measure(); const observer = new ResizeObserver(measure); observer.observe(root); observer.observe(group); return () => observer.disconnect(); }, [vertical, reduceMotion]); // Distance travelled within the current copy, 0 → size. const offset = useMotionValue(0); // 1 = full speed, 0 = stopped. Eased so hovering slows down instead of snapping. const rate = useMotionValue(paused ? 0 : 1); // Pointer over / focus inside, tracked separately so one ending doesn't cancel the other. const holds = React.useRef({ pointer: false, focus: false }); const updateRate = React.useCallback(() => { const held = pauseOnHover && (holds.current.pointer || holds.current.focus); animate(rate, paused || held ? 0 : 1, { duration: 0.5, ease: "easeOut" }); }, [paused, pauseOnHover, rate]); React.useEffect(() => { updateRate(); }, [updateRate]); useAnimationFrame((_, delta) => { const length = size.current; if (!length || !inView || reduceMotion) return; const r = rate.get(); if (r === 0) return; // Clamp delta so a backgrounded tab doesn't jump on return. const next = (offset.get() + (speed * Math.min(delta, 64) * r) / 1000) % length; offset.set(next); }); const translate = useTransform(offset, (o) => (forward ? -o : o - size.current)); const hold = (source: "pointer" | "focus", value: boolean) => { if (holds.current[source] === value) return; holds.current[source] = value; updateRate(); }; const fadeSize = fade === true ? 64 : typeof fade === "number" ? fade : 0; const mask = fadeSize > 0 && !reduceMotion ? `linear-gradient(to ${vertical ? "bottom" : "right"}, transparent, #000 ${fadeSize}px, #000 calc(100% - ${fadeSize}px), transparent)` : undefined; const group = (index: number) => ( <div key={index} ref={index === 0 ? groupRef : undefined} aria-hidden={index > 0 || undefined} inert={index > 0 || undefined} className={cn("flex shrink-0", vertical ? "flex-col" : "items-center", groupClassName)} style={vertical ? { gap, paddingBottom: gap } : { gap, paddingRight: gap }} > {children} </div> ); if (reduceMotion) { return ( <div ref={rootRef} data-slot="marquee" data-direction={direction} className={cn( "flex [scrollbar-width:thin]", vertical ? "flex-col overflow-y-auto" : "overflow-x-auto", className )} style={style} onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave} onFocus={onFocus} onBlur={onBlur} {...props} > {group(0)} </div> ); } return ( <div ref={rootRef} data-slot="marquee" data-direction={direction} className={cn("flex overflow-hidden", vertical && "flex-col", className)} style={{ maskImage: mask, WebkitMaskImage: mask, ...style }} onPointerEnter={(event) => { onPointerEnter?.(event); if (event.pointerType !== "touch") hold("pointer", true); }} onPointerLeave={(event) => { onPointerLeave?.(event); hold("pointer", false); }} onFocus={(event) => { onFocus?.(event); hold("focus", true); }} onBlur={(event) => { onBlur?.(event); if (!event.currentTarget.contains(event.relatedTarget as Node | null)) hold("focus", false); }} {...props} > <motion.div className={cn("flex shrink-0 will-change-transform", vertical ? "h-max flex-col" : "w-max")} style={vertical ? { y: translate } : { x: translate }} > {Array.from({ length: copies }, (_, i) => group(i))} </motion.div> </div> ); }
Usage
import { Marquee } from "@/components/dusk/marquee/marquee"
const logos = ["Nebula", "Quanta", "Lumen", "Vertex", "Stratus"]
export function LogoCloud() {
return (
<Marquee speed={40} gap={32} aria-label="Customers" role="region">
{logos.map((name) => (
<span key={name} className="text-lg font-semibold text-white/60">
{name}
</span>
))}
</Marquee>
)
}Examples
Testimonials with a pause button
Any content works, including cards. fade takes a width in px for the edge mask, and paused lets you wire your own play/pause control, which moving content longer than five seconds should offer.
Maya Chen
@mayabuilds
We rebuilt our pricing page sections in an afternoon and kept our own styles.
Leo Park
@leop
Reduced motion is handled out of the box, which saved us an accessibility pass.
Ama Owusu
@ama.codes
The components are plain React and Tailwind, so code review was quick.
Jonas Weber
@jweber
The marquee loops cleanly at every width. No visible seams.
Priya Nair
@priyanair
Focus states and keyboard support were already there when we checked.
"use client";
import * as React from "react";
import { Pause, Play } from "lucide-react";
import { Marquee } from "@/components/dusk/marquee/marquee";
import { Button } from "@/components/ui/button";
const reviews = [
{ name: "Maya Chen", handle: "@mayabuilds", text: "We rebuilt our pricing page sections in an afternoon and kept our own styles." },
{ name: "Leo Park", handle: "@leop", text: "Reduced motion is handled out of the box, which saved us an accessibility pass." },
{ name: "Ama Owusu", handle: "@ama.codes", text: "The components are plain React and Tailwind, so code review was quick." },
{ name: "Jonas Weber", handle: "@jweber", text: "The marquee loops cleanly at every width. No visible seams." },
{ name: "Priya Nair", handle: "@priyanair", text: "Focus states and keyboard support were already there when we checked." },
];
function initials(name: string) {
return name
.split(" ")
.map((part) => part[0])
.join("");
}
function Review({ name, handle, text }: (typeof reviews)[number]) {
return (
<figure className="w-72 rounded-xl border border-white/10 bg-white/[0.03] p-4">
<div className="flex items-center gap-3">
<span
aria-hidden
className="flex size-9 items-center justify-center rounded-full bg-muted text-xs font-semibold text-foreground"
>
{initials(name)}
</span>
<figcaption className="min-w-0">
<p className="truncate text-sm font-medium text-white">{name}</p>
<p className="truncate text-xs text-white/55">{handle}</p>
</figcaption>
</div>
<blockquote className="mt-3 text-sm leading-relaxed text-white/70">{text}</blockquote>
</figure>
);
}
export default function MarqueeTestimonialsDemo() {
const [paused, setPaused] = React.useState(false);
return (
<div className="w-full max-w-2xl space-y-4">
<Marquee paused={paused} speed={32} fade={96} aria-label="Customer reviews" role="region">
{reviews.map((review) => (
<Review key={review.handle} {...review} />
))}
</Marquee>
<div className="flex justify-center">
<Button variant="outline" size="sm" aria-pressed={paused} onClick={() => setPaused((p) => !p)}>
{paused ? <Play aria-hidden /> : <Pause aria-hidden />}
{paused ? "Play" : "Pause"}
</Button>
</div>
</div>
);
}Vertical columns
direction="up" or "down" scrolls vertically. Give the marquee a height; alternate directions and speeds for a parallax wall.
import { Marquee } from "@/components/dusk/marquee/marquee";
const columns = [
["Realtime sync", "Edge cache", "Zero config", "Type-safe", "Dark mode"],
["Spring physics", "Layout animations", "Reduced motion", "SSR safe", "Tree-shakable"],
["Copy & paste", "Tailwind v4", "shadcn/ui", "Accessible", "Open source"],
];
function Tag({ children }: { children: string }) {
return (
<span className="block rounded-lg border border-white/10 bg-white/[0.03] px-4 py-3 text-center text-sm text-white/70">
{children}
</span>
);
}
export default function MarqueeVerticalDemo() {
return (
<div className="grid h-72 w-full max-w-lg grid-cols-3 gap-3">
{columns.map((tags, i) => (
<Marquee key={i} direction={i % 2 ? "down" : "up"} speed={18 + i * 6} gap={12} className="h-full">
{tags.map((tag) => (
<Tag key={tag}>{tag}</Tag>
))}
</Marquee>
))}
</div>
);
}API Reference
Also accepts any HTML attribute for the root div.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | The items. Rendered once, then cloned as needed to fill the loop. |
| direction | "left" | "right" | "up" | "down" | "left" | Travel direction. up / down make a vertical marquee (set a height). |
| speed | number | 40 | Pixels per second. |
| gap | number | 16 | Space between items and between copies, in px. |
| pauseOnHover | boolean | true | Ease to a stop while hovered or while focus is inside. |
| paused | boolean | false | Stop the marquee, e.g. from your own pause button. |
| fade | boolean | number | true | Mask the edges. true = 64px, or a width in px. |
| groupClassName | string | — | Classes for each copy of the content (the flex row/column). |
Accessibility
- Only the first copy is exposed. The clones are aria-hidden and inert, so screen readers read each item once and Tab never lands on a duplicate link.
- It eases to a stop on hover and whenever focus moves inside, so links and buttons in it are easy to reach. Use paused to add a visible pause control (WCAG 2.2.2).
- With prefers-reduced-motion it renders a single static copy in a natively scrollable row (or column), with no mask hiding the ends.
- Movement is one transform on the track, driven by a Motion value, and it stops while the marquee is off-screen.
- Give it a label (aria-label plus role="region", or wrap it in a labelled section) when the content needs context.