Back to Explore
THE PLAYGROUND · SCROLL & NAVIGATION

Collapsing Header

A large header shrinks to make room for content.

Collapsing HeaderScroll & Navigation · A large header shrinks to make room for content.
SCROLL
FIELD NOTES
Find your rhythmA moment worth noticing.
Make space for ideasA moment worth noticing.
Follow the feelingA moment worth noticing.
Stay curiousA moment worth noticing.
Keep exploringA moment worth noticing.
SCROLL INSIDE PREVIEW · 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 CollapseHeaderDemo() {7  const [scroll, setScroll] = useState(0);8  return <div onScroll={e => setScroll(e.currentTarget.scrollTop)} style={{height: 260, overflowY: "auto"}}>9    <header style={{position: "sticky", top: 0, background: "#202420", height: Math.max(32, 80-scroll/2), color: "white"}}>Field notes</header>10    11    {[0,1,2,3,4,5,6].map(n => <motion.div key={n} style={{...surface, width: 260, height: 80, margin: 12}} >Note {n+1}</motion.div>)}12  </div>;13}

Install: npm install motion. Map scroll progress to the header height. This compact example illustrates the core technique; the styled playground contains additional presentation details.