# Marquee

A row of content that scrolls past on a loop.

Source: [marquee.tsx](https://github.com/jakejarvis/jarvis-ui/blob/main/src/components/ui/marquee.tsx)

```tsx
import {
  AtomIcon,
  BirdIcon,
  BoxIcon,
  CloudIcon,
  FlameIcon,
  HexagonIcon,
  LeafIcon,
  MountainIcon,
} from "lucide-react";

import { Marquee } from "@/components/ui/marquee";

const companies = [
  { name: "Northwind", icon: BirdIcon },
  { name: "Cobalt", icon: HexagonIcon },
  { name: "Evergreen", icon: LeafIcon },
  { name: "Summit", icon: MountainIcon },
  { name: "Nimbus", icon: CloudIcon },
  { name: "Ember", icon: FlameIcon },
  { name: "Quanta", icon: AtomIcon },
  { name: "Crate", icon: BoxIcon },
];

export default function MarqueeLogos() {
  return (
    <Marquee aria-label="Customers" className="w-full max-w-xl [--marquee-gap:--spacing(10)]">
      {companies.map((company) => (
        <div
          key={company.name}
          className="flex items-center gap-2 text-lg font-semibold tracking-tight text-muted-foreground"
        >
          <company.icon className="size-5" aria-hidden />
          {company.name}
        </div>
      ))}
    </Marquee>
  );
}
```

## Installation

Add the registry, once per project:

```bash
npx shadcn@latest registry add @jarvis=https://ui.jarv.is/r/{name}.json
```

Then add the component:

```bash
npx shadcn@latest add @jarvis/marquee
```

## Usage

```tsx
import { Marquee } from "@/components/ui/marquee";

export function CustomerLogos() {
  return (
    <Marquee aria-label="Customers">
      <img src="/logos/northwind.svg" alt="Northwind" className="h-6" />
      <img src="/logos/cobalt.svg" alt="Cobalt" className="h-6" />
      <img src="/logos/evergreen.svg" alt="Evergreen" className="h-6" />
    </Marquee>
  );
}
```

The marquee repeats its children as many times as it takes to fill it, so the loop never shows a
gap. It moves them `speed` pixels per second with the Web Animations API, so the browser runs the
animation off the main thread. Set `--marquee-gap` on the marquee to change the space between
items, and `--marquee-fade` to change how far in from each end the content fades. Turn the fade off
with `fade={false}`.

The marquee slows to a stop while the pointer is over it or a finger touches it, unless you set
`pauseOnHover={false}`. It also stops while something inside it has keyboard focus, and scrolls the
focused element into view. Screen readers read the content once, since the copies are hidden from
them and are left out of the tab order. Users can still click or tap the links and buttons in
every copy.

For users who ask their system to reduce motion, the marquee stays still. If they need to reach
content that doesn't fit, set `drag` or `wheel`, or add a [pause button](#pause-button).
Moving content that runs for more than a few seconds needs a way to stop it.

## Examples

### Reverse

`reverse` moves the content toward the end instead of the start.

```tsx
import { Badge } from "@/components/ui/badge";
import { Marquee } from "@/components/ui/marquee";

const frameworks = ["React", "Vue", "Svelte", "Solid", "Angular", "Astro", "Qwik", "Preact"];
const tools = ["Vite", "Turbopack", "esbuild", "Rollup", "Bun", "Deno", "Node.js", "pnpm"];

export default function MarqueeReverse() {
  return (
    <div className="flex w-full max-w-md flex-col gap-3 [--marquee-gap:--spacing(2)]">
      <Marquee>
        {frameworks.map((name) => (
          <Badge key={name}>{name}</Badge>
        ))}
      </Marquee>
      <Marquee reverse>
        {tools.map((name) => (
          <Badge key={name}>{name}</Badge>
        ))}
      </Marquee>
    </div>
  );
}
```

### Drag and scroll

`drag` lets users grab and fling the marquee, or swipe it on a touch screen. `wheel` lets them
scroll it with a mouse wheel or trackpad. A drag that moves the marquee doesn't count as a click on
the content inside it.

```tsx
import { Marquee } from "@/components/ui/marquee";
import { gradientImage } from "@/examples/data";

const photos = [
  { alt: "Blue and green", image: gradientImage("#7698fd", "#6bd586", 200, 140) },
  { alt: "Yellow and red", image: gradientImage("#f2cf76", "#f17471", 200, 140) },
  { alt: "Light and dark blue", image: gradientImage("#a2bcff", "#3b5cf6", 200, 140) },
  { alt: "Pale and deep green", image: gradientImage("#b8e9c1", "#198b43", 200, 140) },
  { alt: "Cream and gold", image: gradientImage("#f7e5b5", "#cb9f34", 200, 140) },
  { alt: "Pink and crimson", image: gradientImage("#f2bbb7", "#b82d35", 200, 140) },
];

export default function MarqueeDraggable() {
  return (
    <Marquee drag wheel speed={30} className="w-full max-w-xl">
      {photos.map((photo) => (
        <img key={photo.alt} src={photo.image} alt={photo.alt} className="h-28 rounded-lg" />
      ))}
    </Marquee>
  );
}
```

### Vertical

Set `orientation="vertical"` to move the content upward, and give the marquee a height.

```tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Marquee } from "@/components/ui/marquee";
import { people } from "@/examples/data";

const quotes = [
  "Setup took five minutes, and the defaults were already what we wanted.",
  "Our designers and engineers finally agree on what a button looks like.",
  "We replaced three internal libraries with it in a week.",
  "The docs answer the question before I think to ask it.",
  "Dark mode just worked, which has never happened to me before.",
];

export default function MarqueeVertical() {
  return (
    <Marquee orientation="vertical" speed={25} className="h-80 w-full max-w-xs">
      {quotes.map((quote, index) => {
        const person = people[index];
        return (
          <figure
            key={person.value}
            className="flex flex-col gap-3 rounded-lg bg-layer-1 p-4 inset-ring-[0.5px] inset-ring-border-muted"
          >
            <blockquote className="text-sm">{quote}</blockquote>
            <figcaption className="flex items-center gap-2">
              <Avatar size="sm">
                <AvatarImage src={person.image} alt="" />
                <AvatarFallback>{person.initials}</AvatarFallback>
              </Avatar>
              <span className="text-xs text-muted-foreground">{person.name}</span>
            </figcaption>
          </figure>
        );
      })}
    </Marquee>
  );
}
```

### Pause button

`paused` stops the marquee, easing to a stop as it does on hover.

```tsx
"use client";

import { PauseIcon, PlayIcon } from "lucide-react";
import * as React from "react";

import { Button } from "@/components/ui/button";
import { Marquee } from "@/components/ui/marquee";
import { Status } from "@/components/ui/status";

const services = [
  { name: "API", status: "Operational", variant: "success" },
  { name: "Dashboard", status: "Operational", variant: "success" },
  { name: "Builds", status: "Degraded", variant: "warning" },
  { name: "Edge network", status: "Operational", variant: "success" },
  { name: "Webhooks", status: "Outage", variant: "destructive" },
  { name: "Storage", status: "Operational", variant: "success" },
] as const;

export default function MarqueePauseButton() {
  const [paused, setPaused] = React.useState(false);
  return (
    <div className="flex w-full max-w-lg items-center gap-2">
      <Marquee paused={paused} className="min-w-0 flex-1 [--marquee-gap:--spacing(6)]">
        {services.map((service) => (
          <span key={service.name} className="flex items-center gap-2 text-sm">
            {service.name}
            <Status variant={service.variant}>{service.status}</Status>
          </span>
        ))}
      </Marquee>
      <Button
        variant="ghost"
        size="icon-sm"
        aria-label={paused ? "Play" : "Pause"}
        aria-pressed={paused}
        onClick={() => setPaused(!paused)}
      >
        {paused ? <PlayIcon /> : <PauseIcon />}
      </Button>
    </div>
  );
}
```

## Props

| Part | Extends |
| --- | --- |
| `Marquee` | `<div>` |

Base UI's [styling](https://base-ui.com/react/handbook/styling) and [composition](https://base-ui.com/react/handbook/composition) guides say more about `className`, `style` and `render`.

### Marquee

| Prop            | Type                                                     | Default        | Description                                                                                                                                                                               |
| --------------- | -------------------------------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `orientation?`  | `"horizontal" \| "vertical"`                             | `"horizontal"` | The direction the marquee moves in. A vertical marquee needs a height.                                                                                                                    |
| `speed?`        | `number`                                                 | `40`           | How fast the content moves, in pixels per second.                                                                                                                                         |
| `reverse?`      | `boolean`                                                | `false`        | Moves the content toward the end (or down) instead of the start (or up).                                                                                                                  |
| `pauseOnHover?` | `boolean`                                                | `true`         | Slows to a stop while the pointer is over it, or while a finger touches it.                                                                                                               |
| `paused?`       | `boolean`                                                | `false`        | Slows to a stop and stays still, as for a pause button.                                                                                                                                   |
| `drag?`         | `boolean`                                                | `false`        | Lets users drag it with a pointer or swipe it on a touch screen, and fling it on release.                                                                                                 |
| `wheel?`        | `boolean`                                                | `false`        | Lets users scroll it with a mouse wheel or trackpad.                                                                                                                                      |
| `fade?`         | `boolean`                                                | `true`         | Fades out the content at each end.                                                                                                                                                        |
| `className?`    | `string`                                                 | —              | CSS class applied to the element.                                                                                                                                                         |
| `style?`        | `React.CSSProperties`                                    | —              | Style applied to the element.                                                                                                                                                             |
| `render?`       | `ComponentRenderFn<HTMLProps, {}> \| React.ReactElement` | —              | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
