THE PLAYGROUND · SCROLL & NAVIGATION
Accordion Expand / Collapse
A section opens smoothly to reveal its contents.
Accordion Expand / CollapseScroll & Navigation · A section opens smoothly to reveal its contents.
CLICKWhere should I start?
1import { useState } from "react";2import { motion, AnimatePresence } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function AccordionDemo() {7 const [open, setOpen] = useState(false);8 return <div style={{position: "relative", width: 320, minHeight: 200, overflow: "hidden"}}>9 <button aria-expanded={open} onClick={() => setOpen(v => !v)}>Toggle Accordion Expand / Collapse</button>10 <AnimatePresence mode="wait">11 {open && <motion.div key="content" initial={{height:0, opacity:0}} animate={{height:"auto", opacity:1}} exit={{height:0, opacity:0}} transition={{ duration: 0.6, delay: 0, ease: "easeInOut" }} style={{...surface, width: 300, height: "auto", padding: 20}}>12 <p>Details and actions</p><button onClick={() => setOpen(false)}>Close</button>13 </motion.div>}14 </AnimatePresence>15 </div>;16}Install: npm install motion. Animate height and keep the trigger outside the clipped area. This compact example illustrates the core technique; the styled playground contains additional presentation details.