Expand Card

Expandable Card Modal for React

A card that opens into a full article, growing from its place in the page to fill the screen, and shrinks back into its slot when you pull it down, like the App Store's Today tab.

  • Card
  • Gesture
  • Motion

Uses motion, clsx, tailwind-merge

Open in ChatGPTOpen in Claude
width720px
openDuration0.50s
openBounce0.14
closeDuration0.42s
closeBounce0.12
<ExpandCard />

The demo follows as you drag.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Expand Card: A card that opens into a full article, growing from its place in the page to fill the screen, and shrinks back into its slot when you pull it down, like the App Store's Today tab.
This demo, Today Feed: Three stories in different styles: a full-bleed photo, a top-five list and a bold card on a gradient. Tap one, then pull it down from the top, or press Esc, and it lands back in its slot.

1. Install it:
   npx shadcn@latest add @keyframeui/expand-card-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/expand-card-demo.json instead.)
   It adds the demo, components/expand-card-demo.tsx, and the component, components/ui/expand-card.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <ExpandCard> on its own.

3. These props set its feel. Change them before you change the file:
   - width (default 720): Width of the open article on screens 640px and wider, in px, shown over the dimmed page. Narrower screens get the whole screen.
   - openDuration (default 0.5): How long the card takes to grow into the open article, in seconds.
   - openBounce (default 0.14): Bounce of the opening, from 0 (none) to 1.
   - closeDuration (default 0.42): How long the article takes to fly back into its slot, in seconds. The page scrolls the slot into view on the same timing.
   - closeBounce (default 0.12): Bounce of the flight home, from 0 (none) to 1.

4. Don't change, in components/ui/expand-card.tsx:
   - The article flies on motion values that animate its box (`left`, `top`, `boxWidth`, `boxHeight`), never a scale-up, so the cover keeps its real size and nothing re-renders mid-flight. The body is laid out at the open width from the start, so it never reflows.
   - The card is hidden while its article is out, and `finish()` shows it, closes the dialog and hands focus back in one task, so no frame shows both or neither.
   - Going home runs the page scroll that brings the card's slot into view on the home spring's duration (`springs.scroll`), so the article and its slot land together.
   - Esc and the dialog's `cancel` are caught with `preventDefault()` and call `close()`, because letting the dialog close itself skips the flight home.
   - Under reduced motion the article fades in and out in place instead of flying, and the card stays visible behind it.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/expand-card.md

Installation

Add the component on its own with the CLI, or copy the file in by hand.

The CLI writes components/ui/expand-card.tsx and installs motion, clsx and tailwind-merge. It needs the @keyframeui registry in components.json; add it once per project.

npx shadcn@latest add @keyframeui/expand-card

Examples

Finished sections built with Expand Card. Each one installs whole, with the component included.

Changelog With Links

Each post has its own link. Opening one updates the URL, the back button closes it, and loading a post's link opens it directly. The notes load while the cover grows.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Expand Card: A card that opens into a full article, growing from its place in the page to fill the screen, and shrinks back into its slot when you pull it down, like the App Store's Today tab.
This demo, Changelog With Links: Each post has its own link. Opening one updates the URL, the back button closes it, and loading a post's link opens it directly. The notes load while the cover grows.

1. Install it:
   npx shadcn@latest add @keyframeui/expand-card-changelog-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/expand-card-changelog-demo.json instead.)
   It adds the demo, components/expand-card-changelog-demo.tsx, and the component, components/ui/expand-card.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <ExpandCard> on its own.

3. These props set its feel. Change them before you change the file:
   - width (default 720): Width of the open article on screens 640px and wider, in px, shown over the dimmed page. Narrower screens get the whole screen.
   - openDuration (default 0.5): How long the card takes to grow into the open article, in seconds.
   - openBounce (default 0.14): Bounce of the opening, from 0 (none) to 1.
   - closeDuration (default 0.42): How long the article takes to fly back into its slot, in seconds. The page scrolls the slot into view on the same timing.
   - closeBounce (default 0.12): Bounce of the flight home, from 0 (none) to 1.

4. Don't change, in components/ui/expand-card.tsx:
   - The article flies on motion values that animate its box (`left`, `top`, `boxWidth`, `boxHeight`), never a scale-up, so the cover keeps its real size and nothing re-renders mid-flight. The body is laid out at the open width from the start, so it never reflows.
   - The card is hidden while its article is out, and `finish()` shows it, closes the dialog and hands focus back in one task, so no frame shows both or neither.
   - Going home runs the page scroll that brings the card's slot into view on the home spring's duration (`springs.scroll`), so the article and its slot land together.
   - Esc and the dialog's `cancel` are caught with `preventDefault()` and call `close()`, because letting the dialog close itself skips the flight home.
   - Under reduced motion the article fades in and out in place instead of flying, and the card stays visible behind it.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/expand-card.md

Shop

Product cards that open into a product page with close-ups and a size picker. Add something to the bag, then pull the page down to watch the count behind it change.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Expand Card: A card that opens into a full article, growing from its place in the page to fill the screen, and shrinks back into its slot when you pull it down, like the App Store's Today tab.
This demo, Shop: Product cards that open into a product page with close-ups and a size picker. Add something to the bag, then pull the page down to watch the count behind it change.

1. Install it:
   npx shadcn@latest add @keyframeui/expand-card-shop-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/expand-card-shop-demo.json instead.)
   It adds the demo, components/expand-card-shop-demo.tsx, and the component, components/ui/expand-card.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <ExpandCard> on its own.

3. These props set its feel. Change them before you change the file:
   - width (default 720): Width of the open article on screens 640px and wider, in px, shown over the dimmed page. Narrower screens get the whole screen.
   - openDuration (default 0.5): How long the card takes to grow into the open article, in seconds.
   - openBounce (default 0.14): Bounce of the opening, from 0 (none) to 1.
   - closeDuration (default 0.42): How long the article takes to fly back into its slot, in seconds. The page scrolls the slot into view on the same timing.
   - closeBounce (default 0.12): Bounce of the flight home, from 0 (none) to 1.

4. Don't change, in components/ui/expand-card.tsx:
   - The article flies on motion values that animate its box (`left`, `top`, `boxWidth`, `boxHeight`), never a scale-up, so the cover keeps its real size and nothing re-renders mid-flight. The body is laid out at the open width from the start, so it never reflows.
   - The card is hidden while its article is out, and `finish()` shows it, closes the dialog and hands focus back in one task, so no frame shows both or neither.
   - Going home runs the page scroll that brings the card's slot into view on the home spring's duration (`springs.scroll`), so the article and its slot land together.
   - Esc and the dialog's `cancel` are caught with `preventDefault()` and call `close()`, because letting the dialog close itself skips the flight home.
   - Under reduced motion the article fades in and out in place instead of flying, and the card stays visible behind it.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/expand-card.md

Props

cover Required

TypeReact.ReactNode

The card's face, and the top of the open article. It fills the card, then the article's header, at its own size: nothing is scaled, so it uncrops as it widens. Give its text a max width so it wraps the same in both.

children

TypeReact.ReactNode

The article's body, revealed under the cover. Only rendered while open. If it suspends, the cover still animates straight away and fallback shows until the body is ready.

id

Typestring

Gives the article a link of its own, #id. Opening it adds a history entry, so the back button closes it, and loading the link opens it. Also the card's DOM id; with it the card is a link, without it a button.

open / onOpenChange

Typeboolean / (open: boolean) => void

Control it yourself. onOpenChange is also called when the reader opens or closes it.

width

TypenumberDefault720

Width of the open article on screens 640px and wider, in px, shown over the dimmed page. Narrower screens get the whole screen.

coverHeight

Typenumber

Height of the cover in the open article, in px. Defaults to the card's height. Taller suits portrait photos, like products.

openDuration

TypenumberDefault0.5

How long the card takes to grow into the open article, in seconds.

openBounce

TypenumberDefault0.14

Bounce of the opening, from 0 (none) to 1.

closeDuration

TypenumberDefault0.42

How long the article takes to fly back into its slot, in seconds. The page scrolls the slot into view on the same timing.

closeBounce

TypenumberDefault0.12

Bounce of the flight home, from 0 (none) to 1.

className

Typestring

Classes for the card: size, corners, background. Its corners, background and text styles carry into the open article's cover. Other props pass through to the card, a button (or an a with id).

articleClassName

TypestringDefault"bg-background text-foreground"

Classes for the open article, such as its background and text color.

fallback

TypeReact.ReactNode

Shown in place of the body while it suspends. Defaults to a few placeholder lines.