Skip to content
animorio
IT
All components

Card to modal

Cards, Hover, TransitionsGSAP, CSS onlyAdvancedCompressed weight: Demo 5.9 KBGSAP 28 KBFreeDownload the zip

A product card that becomes the details window itself: tapped, it leaves its place, grows to the middle with a small overshoot while the page behind dims, the print at the top grows with it and below the description, the sizes and Add to cart come in one after the other. On closing, the details leave and the window goes back exactly onto the card, to the pixel.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Card to modal" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Card to modal</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- a product card that becomes the window: it grows from its own place to the middle, the page dims,
         the details come in one after the other, and closing takes it back exactly where it was -->
    <div class="cm" data-cm>
      <button class="cm__card" type="button" data-card data-art="tide" data-title="Tidal no. 4" data-price="€38" data-text="Risograph print in two inks on warm recycled stock. Signed and numbered, edition of 120.">
        <span class="cm__art cm__art--tide" aria-hidden="true"><i></i><i></i><i></i></span>
        <span class="cm__meta"><b>Tidal no. 4</b><span>€38</span></span>
      </button>
      <button class="cm__card" type="button" data-card data-art="dune" data-title="Dune study" data-price="€42" data-text="Screen print in three passes on heavy cotton paper. Signed and numbered, edition of 80.">
        <span class="cm__art cm__art--dune" aria-hidden="true"><i></i><i></i><i></i></span>
        <span class="cm__meta"><b>Dune study</b><span>€42</span></span>
      </button>
    </div>

    <div class="cm__dim" data-dim></div>
    <div class="cm__modal" data-modal role="dialog" aria-modal="true" aria-labelledby="cm-title" hidden>
      <span class="cm__art" data-outart aria-hidden="true"><i></i><i></i><i></i></span>
      <button class="cm__close" type="button" data-close aria-label="Close"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8"></path></svg></button>
      <div class="cm__body">
        <span class="cm__meta"><b id="cm-title" data-outtitle>Tidal no. 4</b><span data-outprice>€38</span></span>
        <p class="cm__text" data-in data-outtext></p>
        <div class="cm__sizes" data-in role="radiogroup" aria-label="Size">
          <button type="button" role="radio" aria-checked="false" data-size>A4</button>
          <button type="button" role="radio" aria-checked="true" data-size>A3</button>
          <button type="button" role="radio" aria-checked="false" data-size>A2</button>
        </div>
        <button class="cm__buy" type="button" data-in data-buy>Add to cart</button>
      </div>
    </div>
    <span class="live" aria-live="polite" data-live></span>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

19 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Card to modal” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On white, two cards side by side from a print shop: each has its print in flat shapes, its title and its price. On opening they rise one after the other. Tap a card and it vanishes from its place while, exactly on top, the window appears with the same look: it travels to the middle growing, goes slightly past its size and settles, the print grows taller with it, the page behind dims. Halfway through, the description, the three sizes and the blue Add to cart button come in staggered, rising; at the top right the round close button pops out. Sizes are picked with a tap, on a small bounce. On closing (the round button, a tap outside or Esc) the details go first, then the window shrinks back onto the card, and only then does the real card reappear: the swap cannot be seen. Keyboard focus stays inside the window and at the end goes back to the card.

How it works

Two measurements

On tap the script measures where the card sits inside the stage and where the window will go: at most 300 pixels wide, as tall as its content, in the middle. The window is a single element, filled with the card’s data (title, price, text, print).

The journey

GSAP takes the window’s x, y, width and height from the first measurement to the second, on a light back.out; the print’s height does the same. The real card is hidden with visibility, so it keeps its place in the grid.

The way back

To close, the card is measured again (the page may have changed) and the window goes back to it on a soft ease, with no bounce. When the journey is over the window hides and the card reappears in the same frame.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#2f5bffThe colour of the Add to cart button and of the first print’s ink.
OPENscript.js0.75How long the card takes to grow into the window.
DIMscript.js0.5How much the page behind dims.

Try them in the Playground

When to use it

In a shop’s product grid, for a quick view without leaving the page; in a portfolio’s gallery of work; in a list of articles, recipes, rooms, events: wherever a card has more to say than fits.

On phones

The two cards sit side by side in 292 pixels; the window is at most 300 wide and about 340 tall, the print getting shorter on low screens. It closes with the round button at the top or with a tap outside.

With reduced motion

The window does not travel: it fades in already in the middle, with all its details in place, and fades out. The demo’s pointer does not start.

Pitfalls

  • The window has role dialog and aria-modal: for whoever comes by keyboard focus goes to the close button, Tab cycles only through its controls, Esc closes it and focus goes back to the card it came from.
  • Measurements are in pixels: if the page changes size while the window is open the script puts it back in the middle, and on the way back it measures the card again.
  • Animating width and height makes the page reflow on every frame: fine for a small window like this one; for a full-screen one scale and clip-path are better.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 5.9 KB; the libraries: GSAP 28 KB.

Testing

Tested on 26 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components