Marquee
newAnd they're off. Content that scrolls forever, horizontal or vertical, with a pause on hover and a fade at the edges.
Installation
Usage
<script setup lang="ts">
import { Marquee } from '@/components/ui/marquee'
</script>
<template>
<Marquee pause-on-hover>
<img v-for="logo in logos" :key="logo.alt" :src="logo.src" :alt="logo.alt" class="h-10 shrink-0" />
</Marquee>
</template>
The slot is laid out in a row and repeated repeat times (two by default); a CSS animation slides each copy by its own width plus the gap, so the strip loops without a seam as long as the copies cover the marquee. Give every child shrink-0, and the marquee a width (or a height when vertical). Its content never sizes it: in a box that takes its width from its content, such as a horizontal scroll area, the marquee is as wide as you make it and nothing else. Only the first copy reaches assistive technology and the Tab order: the others are aria-hidden and their links and buttons get tabindex="-1", while the pointer works on every copy. The slot really is rendered repeat times, so a component inside mounts that many times and an id in it repeats.
Set --marquee-gap rather than a gap-* class: the animation moves each copy by its width plus that variable.
A shadow or a ring on an item is cut at the marquee's edge; pad the marquee if it needs room.
Under reduced motion the strip stands still with the first copy in view; in a right-to-left document it runs the other way.
Examples
Pausing
paused stops the animation in place, for a control of your own: content that moves for more than five seconds needs a way to stop it (WCAG 2.2.2). pause-on-hover holds it under the pointer. Keyboard focus inside the marquee always stops it and shows the content from its start, so a Tab reaches something you can see; a mouse click does not.
Reverse
Vertical
orientation="vertical" scrolls a column up. Give the marquee a height.
Repeat
repeat is how many copies are laid out, two by default. Each copy is at least as wide as the marquee, so two always cover it and loop without a seam; one leaves the marquee empty while the copy travels back, and more than two only cost DOM nodes.
Fade
The edges dissolve through a mask, a quarter of the width on each side by default; --marquee-fade sets how much, and :fade="false" turns it off.
Testimonials
Two rows of cards running opposite ways, with a smaller gap and a pause on hover.
Performance
The fade is a mask-image, not a pair of gradient overlays in the page's background colour, so it works on a card, a coloured band or an image as well as on the page. The price is how the browser draws it. A strip without a mask is a finished layer the compositor slides; a masked one cannot be. Every frame the browser draws the moving copies into an off-screen surface and multiplies that surface by the mask, so the cost grows with the marquee's area and with how many run at once. One logo strip is nothing; several full-width rows of cards on a weak phone can drop frames. The mask also dissolves whatever sits near the edges, a card's shadow and a focus ring included.
If that shows, set :fade="false". On a plain background you can draw the fade yourself with two absolutely positioned gradients over the edges, which is what Nuxt UI does, at no cost beyond paint.
API Reference
Marquee
| Prop | Default | Type and description |
|---|---|---|
| as | "div" | AsTag | ComponentThe element or component to render. A |
| pauseOnHover | false | booleanHolds the animation in place while the pointer is over the marquee. Off by default. Keyboard focus inside always stops it. |
| paused | false | booleanStops the animation in place, for a pause control of your own. Off by default. |
| reverse | false | booleanRuns the animation the other way. |
| orientation | "horizontal" | MarqueeOrientation
|
| repeat | 2 | numberHow many copies of the content are laid out, 2 by default; each is at least as wide as the marquee, so two always loop without a seam. |
| fade | true | booleanDissolves the edges through a mask, |
| Slot | Scope and description |
|---|---|
| default | {}The content, laid out in a row (or a column) and repeated |
Props
- as
"div" AsTag | ComponentThe element or component to render. A<div>by default. There is noas-child, because the marquee renders its own copies of the content.- pauseOnHover
false booleanHolds the animation in place while the pointer is over the marquee. Off by default. Keyboard focus inside always stops it.- paused
false booleanStops the animation in place, for a pause control of your own. Off by default.- reverse
false booleanRuns the animation the other way.- orientation
"horizontal" MarqueeOrientationhorizontalscrolls along the row,verticalup a column; a vertical marquee needs a height.horizontalby default.- repeat
2 numberHow many copies of the content are laid out, 2 by default; each is at least as wide as the marquee, so two always loop without a seam.- fade
true booleanDissolves the edges through a mask,--marquee-fadeon each side. On by default; see Performance on the page before leaving it on for a wide marquee.
Slots
- default
{}The content, laid out in a row (or a column) and repeatedrepeattimes; give each childshrink-0.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| marquee | data-orientation | The root; clips the copies. |
| marquee-content | aria-hidden | One copy of the slot; every copy after the first carries aria-hidden, and its focusable elements tabindex="-1". |
CSS variables
Set with a class on the root: class="[--marquee-duration:40s]".
| Variable | Default | Description |
|---|---|---|
| --marquee-gap | --spacing(16) | The space between items and between copies. |
| --marquee-duration | 20s | How long one copy takes to travel its own length; lower is faster. |
| --marquee-fade | 25% | How much of each edge dissolves, a length or a percentage of the marquee. |