Copies›Perspective Carousel

Perspective Carousel

Cover-flow carousel where the center card is flat and large while neighbours shrink and turn away; wraps around, drag, arrow keys, dots and autoplay.

Copy a ready prompt for Claude Code, Codex or Cursor

Seen on

Skiper UI

Dependencies

reacttailwindcssmotion

Interaction type

drag

Install via CLI

pnpm dlx shadcn@latest add @copia/perspective-carousel

Without the namespace: npx shadcn@latest add https://copia-ui.vercel.app/r/perspective-carousel.json

How to use

demo.tsx
import { PerspectiveCarousel, type PerspectiveCarouselProps } from "./perspective-carousel"

/** Free photos from Lummi (lummi.ai); authors in meta.json → assets. */
const PHOTOS = ["crimson-contemplation", "artistic-orchid", "elegant-red-portrait", "white-flowers-on-black", "red-light-portrait", "fiery-profile"]

const items = PHOTOS.map((name) => (
  // eslint-disable-next-line @next/next/no-img-element
  <img key={name} src={`/demo/perspective-carousel/${name}.webp`} alt="" draggable={false} className="size-full object-cover" />
))

export default function Demo(props: Pick<PerspectiveCarouselProps, "size" | "spacing" | "autoplay">) {
  return (
    <div className="grid flex-1 place-items-center overflow-hidden p-6">
      <PerspectiveCarousel size={200} autoplay={1200} {...props} items={items} pauseOnHover={false} label="Albums" />
    </div>
  )
}

Customization

Use the sliders button at the top right of the preview to tweak size, spacing, autoplay live and copy the generated JSX.

Props

PropTypeDefaultDescription
itemsReactNode[]-Cards (covers, images, anything).
sizenumber220Card size in pixels.
spacingnumber0.78Distance between card centers as a fraction of size.
autoplaynumber-Advance every N ms; pauses on hover.
pauseOnHoverbooleantruePause autoplay while hovered.
labelstring"Carousel"Accessible name.

Attribution

Inspired by Skiper UI. Recreated by Copia.

Demo images by pablostanley, ms.designs.0711, axelnascimentto, clemara_studio, harshworks, ibis_design.

Read how it was reverse engineered

Source code

perspective-carousel.tsx
"use client"

import { useCallback, useEffect, useState } from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"

export type PerspectiveCarouselProps = {
  items: React.ReactNode[]
  /** Card width in pixels (cards are square). */
  size?: number
  /** Horizontal distance between card centers, as a fraction of `size`. */
  spacing?: number
  /** Advance automatically every N ms. Pauses on focus, after any interaction and with reduced motion. */
  autoplay?: number
  /** Pause autoplay while the pointer is over the carousel. */
  pauseOnHover?: boolean
  /** Accessible name of the carousel. */
  label?: string
  className?: string
}

const SPRING = { type: "spring", bounce: 0.18, duration: 0.7 } as const

/** Cover-flow style carousel: the center card is large and flat, neighbours shrink and turn away. */
export function PerspectiveCarousel({ items, size = 220, spacing = 0.78, autoplay, pauseOnHover = true, label = "Carousel", className }: PerspectiveCarouselProps) {
  const [active, setActive] = useState(0)
  const [paused, setPaused] = useState(false)
  const [interacted, setInteracted] = useState(false)
  const reduceMotion = useReducedMotion()
  const count = items.length
  const go = useCallback((index: number) => setActive(((index % count) + count) % count), [count])
  // User-driven navigation stops autoplay for good (WCAG 2.2.2).
  const navigate = (index: number) => {
    setInteracted(true)
    go(index)
  }

  useEffect(() => {
    if (!autoplay || paused || interacted || reduceMotion) return
    const id = setInterval(() => go(active + 1), autoplay)
    return () => clearInterval(id)
  }, [autoplay, paused, interacted, reduceMotion, active, go])

  return (
    <div
      role="region"
      aria-roledescription="carousel"
      aria-label={label}
      tabIndex={0}
      onKeyDown={(e) => {
        if (e.key === "ArrowRight") navigate(active + 1)
        if (e.key === "ArrowLeft") navigate(active - 1)
      }}
      onPointerEnter={() => pauseOnHover && setPaused(true)}
      onPointerLeave={() => setPaused(false)}
      onFocus={() => setPaused(true)}
      onBlur={() => setPaused(false)}
      className={cn("flex flex-col items-center gap-5 outline-none focus-visible:ring-2 focus-visible:ring-ring", className)}
    >
      <motion.div
        className="relative cursor-grab touch-pan-y active:cursor-grabbing"
        style={{ width: size * (1 + spacing * 2.4), height: size * 1.1, perspective: 1200 }}
        drag="x"
        dragConstraints={{ left: 0, right: 0 }}
        dragElastic={0.12}
        onDragEnd={(_, info) => {
          if (info.offset.x < -40) navigate(active + 1)
          else if (info.offset.x > 40) navigate(active - 1)
        }}
      >
        {items.map((item, i) => {
          // Shortest signed distance from the active card, so the carousel wraps around.
          let offset = i - active
          if (offset > count / 2) offset -= count
          if (offset < -count / 2) offset += count
          const distance = Math.abs(offset)
          return (
            <motion.button
              key={i}
              type="button"
              aria-label={`Item ${i + 1} of ${count}`}
              aria-current={offset === 0}
              tabIndex={-1}
              onClick={() => navigate(i)}
              className="absolute top-1/2 left-1/2 overflow-hidden rounded-md shadow-2xl"
              style={{ width: size, height: size, marginLeft: -size / 2, marginTop: -size / 2, zIndex: 10 - distance }}
              initial={false}
              animate={{
                x: offset * size * spacing,
                scale: offset === 0 ? 1 : Math.max(0.55, 0.82 - (distance - 1) * 0.12),
                rotateY: reduceMotion ? 0 : Math.max(-40, Math.min(40, -offset * 22)),
                opacity: distance > 2 ? 0 : 1,
                filter: `brightness(${offset === 0 ? 1 : 0.7})`,
              }}
              transition={reduceMotion ? { duration: 0 } : SPRING}
            >
              {item}
            </motion.button>
          )
        })}
      </motion.div>

      <div className="flex gap-1.5" role="tablist" aria-label="Choose item">
        {items.map((_, i) => (
          <button
            key={i}
            type="button"
            role="tab"
            aria-selected={i === active}
            aria-label={`Go to item ${i + 1}`}
            onClick={() => navigate(i)}
            className={cn("h-1.5 rounded-full transition-all", i === active ? "w-4 bg-foreground" : "w-1.5 bg-muted-foreground/40 hover:bg-muted-foreground")}
          />
        ))}
      </div>
    </div>
  )
}

Keep in mind

Most components here are recreations of the best interfaces out there. We don't claim to be the original creators: this is our attempt to reverse engineer, replicate and often add a few features. We credit everyone we can; if we missed someone, let us know.

Contact

Found a bug or a missing credit? Open an issue

License & usage

  • — Free to use and modify in personal and commercial projects (MIT).
  • — No attribution required, but a link back to Copia is appreciated.
  • — Demo images are not part of the license; replace them with your own.
PreviousGlow Border ButtonNext Progressive Blur