Marquee
无限跑马灯
A row of items travels continuously, with the next copy entering as the first passes out of view.
Where to use it
Show a row of partner logos, short testimonials, or items that users can pause to read. Give repeated items equal visual weight and let readers pause the row whenever individual names matter.
Practical example
A local festival puts its community sponsors in a looping strip beneath the event schedule. A visitor pauses the strip to find the bookshop that is hosting the next reading.
Also called
- Infinite Marquee
AI prompt
Add a seamless Marquee to [target row]. Repeat the visual group and move by exactly one group width per cycle, including its spacing. Expose the content once to assistive technology and provide a visible pause control. Use a stationary row with reduced motion and ensure the items stay accessible on narrow screens.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Marquee</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.marquee-window {
width: 100%;
padding-block: 16px;
overflow: hidden;
mask-image: linear-gradient(90deg, transparent, #000 13%, #000 87%, transparent);
}
.marquee-track { display: flex; width: max-content; animation: marquee 7s linear infinite; }
.marquee-items { display: flex; gap: 8px; margin: 0; padding: 0 8px 0 0; list-style: none; }
.marquee-items li {
display: flex;
align-items: center;
gap: 5px;
min-width: 82px;
padding: 9px;
border: 1px solid #655889;
border-radius: 9px;
background: #2a2443;
color: #eee8ff;
font-size: 13px;
font-weight: 650;
}
.marquee-items i { width: 10px; height: 10px; border: 2px solid #c3b0ff; border-radius: 50%; }
.marquee-items li:nth-child(2) i { border-radius: 2px; transform: rotate(30deg); }
.marquee-items li:nth-child(3) i { border-radius: 2px 7px 2px 7px; }
.marquee-items li:nth-child(4) i { border-radius: 0; color: #c3b0ff; background: currentColor; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
/* One complete group creates a seamless handoff to the duplicate. */
@keyframes marquee { to { transform: translateX(-50%); } }
.loop-example {
display: grid;
gap: 12px;
justify-items: center;
width: min(100%, 290px);
}
.loop-example [data-motion] { animation-play-state: paused; }
.loop-example[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.loop-example [data-motion] { animation: none; }
.loop-example [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="loop-example">
<div class="marquee-window" aria-label="Example brand list">
<div class="marquee-track" data-motion>
<ul class="marquee-items" role="list">
<li><i></i>Orbit</li>
<li><i></i>Bloom</li>
<li><i></i>Prism</li>
<li><i></i>Field</li>
</ul>
<ul class="marquee-items" aria-hidden="true">
<li><i></i>Orbit</li>
<li><i></i>Bloom</li>
<li><i></i>Prism</li>
<li><i></i>Field</li>
</ul>
</div>
</div>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
</div>
</main>
<script>
const example = document.querySelector('.loop-example');
const toggle = example.querySelector('[data-loop-toggle]');
toggle.addEventListener('click', () => {
const playing = example.toggleAttribute('data-playing');
toggle.textContent = playing ? "Pause demo" : "Play demo";
});
</script>
</body>
</html>Original example by UI Skills