Marquee

new

And they're off. Content that scrolls forever, horizontal or vertical, with a pause on hover and a fade at the edges.

Demo

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.

Pause on hover

Reverse

Reverse

Vertical

orientation="vertical" scrolls a column up. Give the marquee a height.

Vertical

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.

Repeat

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.

Fade

Testimonials

Two rows of cards running opposite ways, with a smaller gap and a pause on hover.

Testimonials
“The parts compose the way our designers draw them. No prop archaeology.”
AB
Ada ByronEngineering lead
“One size scale for every control. Our forms finally line up.”
GM
Grace MurrayFrontend developer
“Copied the source in, changed three classes, shipped. That is the whole story.”
LB
Linus BenedictFounder
“Colour is one axis and it works everywhere. We deleted a theme file.”
MH
Margaret HamiltonDesign systems
“Swipe views and drawers feel native on a phone. Nothing else we tried did.”
TB
Tim BernersCTO
“The parts compose the way our designers draw them. No prop archaeology.”
AB
Ada ByronEngineering lead
“One size scale for every control. Our forms finally line up.”
GM
Grace MurrayFrontend developer
“Copied the source in, changed three classes, shipped. That is the whole story.”
LB
Linus BenedictFounder
“Colour is one axis and it works everywhere. We deleted a theme file.”
MH
Margaret HamiltonDesign systems
“Swipe views and drawers feel native on a phone. Nothing else we tried did.”
TB
Tim BernersCTO

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

Data attributes

data-slotAttributesDescription
marqueedata-orientationThe root; clips the copies.
marquee-contentaria-hiddenOne 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]".

VariableDefaultDescription
--marquee-gap--spacing(16)The space between items and between copies.
--marquee-duration20sHow long one copy takes to travel its own length; lower is faster.
--marquee-fade25%How much of each edge dissolves, a length or a percentage of the marquee.

Changelog

  1. registry 0.24.1

    35a5371 — No component styles an element through a :has() on its parent or group any more. Chrome restyles the whole subtree of every :has() anchor above a node that is added or removed, once some rule puts :has() away from the element it styles: a page wrapped in one such anchor recalculated every element for each list row it mounted. The Dialog, Drawer and Tour headers, the InputGroup and InputNumber insets, the Combobox clear button, the InputFloating notch, a FieldLabel beside a disabled checkbox or radio, the Rating ring, and the Slider and ScrollArea examples now read their neighbours with ~ or a :has() on the element itself. The InputGroup addons fade through a variable that the group sets. FileUpload, Image, Marquee and DataTable mark the state on an element instead: the hidden input's focus, an ImageError inside, keyboard focus, and the body above pinned bottom rows. scripts/has-selectors.test.ts keeps the pattern out.

    useSwipeSnap no longer flushes styles for an instant move that leaves the offset where it is, such as new points at rest.

  2. core 0.17.1

    35a5371 — No component styles an element through a :has() on its parent or group any more. Chrome restyles the whole subtree of every :has() anchor above a node that is added or removed, once some rule puts :has() away from the element it styles: a page wrapped in one such anchor recalculated every element for each list row it mounted. The Dialog, Drawer and Tour headers, the InputGroup and InputNumber insets, the Combobox clear button, the InputFloating notch, a FieldLabel beside a disabled checkbox or radio, the Rating ring, and the Slider and ScrollArea examples now read their neighbours with ~ or a :has() on the element itself. The InputGroup addons fade through a variable that the group sets. FileUpload, Image, Marquee and DataTable mark the state on an element instead: the hidden input's focus, an ImageError inside, keyboard focus, and the body above pinned bottom rows. scripts/has-selectors.test.ts keeps the pattern out.

    useSwipeSnap no longer flushes styles for an instant move that leaves the offset where it is, such as new points at rest.

  3. registry 0.20.0

    250226f — New Marquee: content that scrolls forever. The slot is repeated repeat times (two by default) and slid by core's animate-marquee; copies after the first are aria-hidden with their focusable elements out of the Tab order, while the pointer works on every copy. paused stops it for a control of your own, pause-on-hover holds it under the pointer, keyboard focus inside stops it, reverse runs it the other way, orientation="vertical" scrolls a column, and fade dissolves the edges through a mask that works on any background. --marquee-gap, --marquee-duration and --marquee-fade tune it from a class.