Back to Explore
THE PLAYGROUND · SCROLL & NAVIGATION

Horizontal Card Stack

Layered cards move horizontally through a collection.

Horizontal Card StackScroll & Navigation · Layered cards move horizontally through a collection.
DRAG
03A better rhythm.
02A new direction.
01A fresh start.
DRAG TO INTERACT · 600 ms
1import { useState } from "react";2import { motion } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function CardStackDemo() {7  const [dismissed, setDismissed] = useState(false);8  const [rotation, setRotation] = useState(0);9  return <div style={{width: 320, overflow: "hidden"}}>10    <button onClick={() => {setDismissed(false); setRotation(0);}}>Reset</button>11    {!dismissed && <motion.div style={surface} drag="x" dragConstraints={{left: 0, right: 0, top: 0, bottom: 0}} dragElastic={0.25} animate={{rotate: rotation}} transition={{ type: "spring", stiffness: 180, damping: 14, mass: 1 }}12      onDrag={(_, info) => undefined}13      onDragEnd={(_, info) => {  }}>Drag me</motion.div>}14    15  </div>;16}

Install: npm install motion. Offset each card to preserve depth and continuity. This compact example illustrates the core technique; the styled playground contains additional presentation details.