Marquee
effect · text · T0 · v1.0.0 · readyAbout
Repeats its content side by side and slides the row continuously, looping seamlessly. It pauses while hovered or while focus is inside, and stands still under reduced motion. The repeated copies are hidden from assistive technology and keyboard focus.
Hover the rows to pause them.
Layers
- Native
- No gated feature: supported everywhere.
- Static
- The first copy of the content stands still, clipped at the edge.
Skin
| Variable | Default | Meaning |
|---|---|---|
--marquee-duration | 20s | Time for the row to move by one copy of the content: longer content moves faster at the same duration. |
--marquee-gap | 2rem | Space between items and between copies. |
Accessibility
Static layer: the row stands still.
WCAG 2.2.2: hover and focus pause the row, but an essential marquee also needs a visible pause control from the host.
Sources
- reel · thedesignshop.tds · "Cursor with Context" reel; technique only (P6).
Code
Self-contained: copy every file, keeping the folder structure.
mechanism.module.css/* web-effects marquee 1.0.0 · MIT-0 */
/* Mechanism of the marquee (D2.8, D3.11), shared by both styling variants.
.track holds `copies` identical .group elements side by side (copies count set inline as
--_marquee-copies). Moving the track by one group, -100% / copies of its own width, lands on
an identical picture, so the loop is seamless. L1: a CSS animation, which every supported
browser runs, so the native layer has no feature gate and there is no L2. L3 (base rules):
the track stands still. */
.root {
--_marquee-duration: var(--marquee-duration, 20s);
--_marquee-gap: var(--marquee-gap, 2rem);
overflow: hidden;
/* Width comes from the container, never from the (much wider) track: without this, a grid or
flex track sized to its content would grow to the track's width. */
contain: inline-size;
}
.track {
display: flex;
width: max-content;
}
/* The gap also trails each group, so the seam between copies matches the gap inside them. */
.group {
display: flex;
flex-shrink: 0;
align-items: center;
gap: var(--_marquee-gap);
padding-inline-end: var(--_marquee-gap);
}
@keyframes slide {
to {
transform: translateX(calc(-100% / var(--_marquee-copies)));
}
}
/* L1 native (gated on the override attribute, D3.6a). */
:root:not([data-fx-layer]) .track,
:root[data-fx-layer="native"] .track {
animation: slide var(--_marquee-duration) linear infinite;
}
.root[data-reverse] .track {
animation-direction: reverse;
}
/* Hover or focus inside pauses the row (WCAG 2.2.2, partly). */
.root:hover .track,
.root:focus-within .track {
animation-play-state: paused;
}
/* L3 under reduced motion (unless forced). */
@media (prefers-reduced-motion: reduce) {
:root:not([data-fx-layer]) .track {
animation: none;
}
}
tailwind/Marquee.tsx// web-effects marquee 1.0.0 · MIT-0
import type { ReactNode } from "react";
import mechanism from "../mechanism.module.css";
import { Track } from "../track";
/**
* Slides `children` sideways without end. `copies`: how many times the content is repeated; one
* copy must be at least as wide as the marquee, or a gap shows before the loop restarts.
*/
export function Marquee({
children,
copies = 2,
reverse = false,
className = "",
}: {
children: ReactNode;
copies?: number;
reverse?: boolean;
className?: string;
}) {
return (
<div
data-reverse={reverse || undefined}
className={`${mechanism.root} w-full ${className}`}
>
<Track copies={copies}>{children}</Track>
</div>
);
}
track.tsx// web-effects marquee 1.0.0 · MIT-0
import type { CSSProperties, ReactNode } from "react";
import mechanism from "./mechanism.module.css";
// The moving track, shared by both styling variants (P8): `copies` groups of the same content.
// Only the first is exposed; the others are aria-hidden and inert (no focus, no clicks).
export function Track({
children,
copies,
}: {
children: ReactNode;
copies: number;
}) {
return (
<div
className={mechanism.track}
style={{ "--_marquee-copies": copies } as CSSProperties}
>
{Array.from({ length: copies }, (_, index) => (
<div
key={index}
className={mechanism.group}
aria-hidden={index > 0 || undefined}
inert={index > 0 || undefined}
>
{children}
</div>
))}
</div>
);
}