Skip to content
animorio
IT
All components

Flipping card form

Forms, HoverGSAP, CSS onlyMediumCompressed weight: Demo 9.5 KBGSAP 28 KBFreeDownload the zip

A payment form on white with the card drawn above it: the digits of the number rise onto the card one by one in groups of four, the name and the expiry date write themselves as you type and a frame of light moves onto the part you are filling in. On the security code the card turns over to show its back, a wrong field shakes and turns red, and the Pay button lights up only when everything is right.

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>
<!--
  "Flipping card form" 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>The card form that flips</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 payment form on white: the card on top writes itself while you type, and turns over when the cursor reaches the
         security code -->
    <section class="pay" data-pay aria-label="Card payment">
      <div class="scene" data-scene>
        <div class="card" data-card>
          <div class="face face--front" data-front>
            <span class="glare" data-glare aria-hidden="true"></span>
            <div class="front__top">
              <span class="bank" data-bank>Tarnley</span>
              <svg class="wave" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.5 7.5a6.5 6.5 0 0 1 0 9M12 5a10 10 0 0 1 0 14M15.5 2.8a13 13 0 0 1 0 18.4"></path></svg>
            </div>
            <span class="chip" aria-hidden="true"><i></i><i></i><i></i></span>
            <div class="num" data-num aria-hidden="true"></div>
            <div class="front__bottom">
              <div class="field-on-card" data-on="name">
                <span class="tiny">Card holder</span>
                <span class="holder" data-holder>Your name</span>
              </div>
              <div class="field-on-card" data-on="exp">
                <span class="tiny">Expires</span>
                <span class="exp" data-exp aria-hidden="true"></span>
              </div>
              <svg class="mark" viewBox="0 0 40 24" aria-hidden="true"><path d="M6 20 13 4h4L10 20Z"></path><path d="M15 20 22 4h4l-7 16Z"></path><path d="M24 20 31 4h4l-7 16Z"></path></svg>
            </div>
          </div>
          <div class="face face--back" data-back>
            <span class="band" aria-hidden="true"></span>
            <div class="sign">
              <span class="sign__strip" aria-hidden="true"></span>
              <span class="cvc" data-cvcshow aria-hidden="true"></span>
            </div>
            <p class="back__note">This card belongs to Tarnley. If found, please return it to any branch.</p>
          </div>
          <span class="focusbox" data-focusbox aria-hidden="true"></span>
        </div>
        <span class="shadow" data-shadow aria-hidden="true"></span>
      </div>

      <form class="form" data-form novalidate autocomplete="off">
        <label class="in in--wide" data-box="num">
          <span class="in__label" data-label>Card number</span>
          <input data-in="num" inputmode="numeric" maxlength="19" spellcheck="false" aria-label="Card number">
        </label>
        <label class="in in--wide" data-box="name">
          <span class="in__label" data-label>Name on card</span>
          <input data-in="name" maxlength="24" spellcheck="false" aria-label="Name on card">
        </label>
        <div class="row">
          <label class="in" data-box="exp">
            <span class="in__label" data-label>Expiry</span>
            <input data-in="exp" inputmode="numeric" maxlength="5" placeholder="MM/YY" aria-label="Expiry date">
          </label>
          <label class="in in--cvc" data-box="cvc">
            <span class="in__label" data-label>CVC</span>
            <input data-in="cvc" inputmode="numeric" maxlength="3" aria-label="Security code">
          </label>
          <button class="paybtn" type="submit" data-paybtn disabled>
            <span class="paybtn__fill" data-fill aria-hidden="true"></span>
            <svg class="paybtn__ring" data-ring viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="7"></circle></svg>
            <svg class="paybtn__check" data-check viewBox="0 0 20 20" aria-hidden="true"><path d="M4.8 10.4 8.4 14l6.8-7.6" pathLength="1"></path></svg>
            <span class="paybtn__label" data-paylabel>Pay</span>
          </button>
        </div>
      </form>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></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.

31 values to change

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 “Flipping card form” 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 a white background there is a drawn payment card, very dark violet with a light sheen at the top, the name of an invented bank, Tarnley, the gold chip, the contactless sign and a mark of three slanted bars; below it the form with the Card number, Name on card, Expiry and CVC fields, and beside them a grey, switched-off Pay button. As you type the number each digit rises onto the card from below, in place of its dash, in groups of four; the name writes itself in capitals one letter at a time, so does the expiry, and a thin frame of light glides across the card to the part you are filling in. With the pointer over it the card tilts slightly towards it and the glare follows. When the focus reaches the CVC the card turns over in 3D to show its back, with the magnetic stripe, the signature strip and the code writing itself in its white box; going back to another field turns it round again. A number that fails the check or a card that has already expired makes the field shake, turn red and say what is wrong. When everything is right the button fills with black from the left and lights up; pressed, a ring spins with Processing, then it turns green with the check and Paid and the card lifts a little. A drawn pointer does it all by itself, gets the expiry wrong on purpose, fixes it, pays and starts again; it also really works, with mouse, touch and keyboard.

How it works

A card with two faces

The card is an element with transform-style preserve-3d and two faces with backface-visibility hidden, the back already turned by 180 degrees. GSAP does not animate the card directly: it moves an object holding flip, tilt and lift, and on every ticker frame they are combined into one transform, so the CVC flip and the tilt towards the pointer never cancel each other out.

Digits that rise

Each place of the number is a small window with overflow hidden, holding a grey dash and the digit. When a digit arrives it comes in from below with back.out while the dash drops and fades; deleting it plays the move in reverse. The number is formatted in groups of four both in the field and on the card.

The frame that follows the field

A thin frame sits over the card and, at every change of field, GSAP takes it on a short spring to the position and size of the right part, number, name or expiry, read with offsetLeft and offsetWidth. On resize it goes back into place, because the card changes size with the box.

Real checks

The number has to pass the Luhn check, the expiry needs a real month and must not be in the past, the CVC wants three digits. A wrong field, when you leave it, shakes on a timeline of dampening moves and turns red with the reason written in place of its label; the button lights up only when all four fields are right.

The autopilot

A drawn pointer clicks the fields and types, pausing between one group of four digits and the next, gets the expiry wrong on purpose, fixes it, goes to the CVC and pays; it all sits on one timeline that pauses while the payment runs. As soon as the page is really touched the autopilot stops and the form answers whoever is using it.

Values to change

NameFileDefaultWhat it changes
BANKscript.js"Tarnley"The name of the invented bank written on the card.
HOLDERscript.js"Lior Brandt"The name the autopilot types.
FLIP_TIMEscript.js0.8The seconds the card takes to turn over.
TYPE_SPEEDscript.js1How fast the autopilot types.
DIGIT_RISEscript.js1How far the digits rise as they reach the card (0 = none).
SHAKEscript.js1How much a wrong field shakes (0 = none).
TILTscript.js1How much the card tilts towards the pointer.

Try them in the Playground

When to use it

For the card step of a checkout, a subscription or a booking: whoever pays sees the card fill in at once, understands where the security code is and knows what to fix before pressing Pay.

On phones

The same animation: the card is sized on both the width and the height of the box, the fields get a little shorter and a tap does what the pointer does; the numeric keyboard opens by itself for the number, expiry and CVC.

With reduced motion

No flip, tilt or shake: the digits and letters fade in, the card goes from front to back with a cross-fade, the wrong field turns red without moving and the frame moves by fading out and in again.

Pitfalls

  • The card flip and the tilt towards the pointer touch the same transform: animated with two separate tweens on the same element, the last one cancelled the other. That is why GSAP moves an object and the ticker writes a single transform.
  • The autopilot does not call focus() on the real fields: in a card inside a page the browser scrolled the whole page to the field. The autopilot’s focus is just a class on the field, the real focus stays with whoever uses the keyboard.
  • The frame on the card has to be measured with offsetLeft and offsetTop, not getBoundingClientRect: while the card is tilted or halfway through the flip, the rectangle the browser returns is the one distorted by perspective.
  • The value has to be formatted before it is written into the field, or the caret jumps to the end at every added space: the field is rewritten only when the formatted text differs from what was typed.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 25 October 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