
The elastic button
Buttons, Hover, Text
The phone number field of a sign-up, on very light grey: as you type each digit springs in from below and the country’s brackets, spaces and dashes open up between the groups by themselves. Type a plus and a code and the country switches by itself, the code rolls and the pill widens; the menu offers six countries. If the number is short the field shakes and says how many digits are missing, when it is whole a green check draws itself and Send code wakes up and sends.
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>
<!--
"Self-formatting phone field" 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 phone number field that formats itself</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">
<!-- the phone field of a sign-up: the digits fall into their groups as you type, the country code switches by itself
when you type a plus, and once the number is whole a check draws itself and Send code wakes up -->
<form class="phone" data-form autocomplete="off" novalidate>
<label class="phone__label" for="tel">Phone number</label>
<div class="field" data-field>
<div class="country" data-country-wrap>
<button class="country__btn" type="button" data-country aria-haspopup="listbox" aria-expanded="false" aria-label="Country code">
<span class="country__iso" data-iso>US</span>
<span class="country__code"><span class="country__roll" data-code>+1</span></span>
<svg class="country__chev" viewBox="0 0 12 12" aria-hidden="true"><path d="M3 4.6 6 7.6l3-3"></path></svg>
</button>
<ul class="menu" data-menu role="listbox" aria-label="Country code"></ul>
</div>
<span class="field__rule" aria-hidden="true"></span>
<div class="digits">
<input class="digits__input" id="tel" type="tel" inputmode="tel" data-input aria-describedby="hint" spellcheck="false">
<div class="digits__show" data-show aria-hidden="true"><span class="digits__ph" data-ph></span><span class="caret" data-caret></span></div>
</div>
<span class="ok" data-ok aria-hidden="true">
<svg viewBox="0 0 20 20"><circle cx="10" cy="10" r="9"></circle><path data-tick d="M6 10.4 8.7 13 14 7.4" pathLength="1"></path></svg>
</span>
</div>
<p class="hint" id="hint" data-hint aria-live="polite"><span data-hint-text>We’ll text you a six-digit code.</span></p>
<button class="send" type="submit" data-send disabled>
<span class="send__label" data-send-label>Send code</span>
<svg class="send__spin" data-spin viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="7"></circle></svg>
<svg class="send__done" data-done viewBox="0 0 20 20" aria-hidden="true"><path d="M5.5 10.4 8.6 13.4 14.5 7" pathLength="1"></path></svg>
</button>
</form>
<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>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.
20 values to change
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 “Self-formatting phone field” from Animorio and fit it into my siteUnderneath is a real input type="tel", transparent, with its caret hidden: it takes the keyboard, copy and paste and the phone’s keypad. On every input event its value becomes the state (the country and the digits), and on top, in a layer that ignores the pointer, the digits are drawn one by one in spans with fixed-width figures.
Each country has its pattern, like (###) ###-#### or #### ######: walking the pattern, each # takes a digit, while separators only appear when the digit after them arrives. Every piece has a key, its position and its digit, so when the number is rebuilt we know who stays, who arrives and who leaves.
Before rebuilding the number we measure where each span is; afterwards, the ones that stayed start from their old place and return to zero on a short spring (back.out): when a bracket or a dash opens, the digits already typed slide aside instead of jumping. New ones rise by 11 pixels, deleted ones drop where they were, pinned in absolute position.
If the value starts with a plus we look for the countries whose code begins the digits, the longest first: when one is found the country changes, the code in the tag rolls (the old one goes up, the new one comes from below) and the pill’s width animates from the old size to the new; the digits after the code stay in the field.
With all the digits the border turns green, the check draws itself with stroke-dashoffset and Send code goes from grey to black with a bounce; with fewer digits sending shakes the field and the help line says how many are missing. Pressed, a timeline squeezes the button, spins the ring for SEND_TIME seconds, draws the check and writes Code sent.
| Name | File | Default | What it changes |
|---|---|---|---|
START_COUNTRY | script.js | US | The country the field starts from: US, GB, IT, DE, FR or JP. |
TYPE_SPEED | script.js | 1 | How fast the autopilot types. |
SPRING | script.js | 1 | How much the digits bounce as they arrive and slide (0 = no bounce). |
SEND_TIME | script.js | 1.1 | The seconds Send code spends sending. |
VALID | script.js | #1f9d55 | The green of a valid number. |
BUTTON | script.js | #111113 | The colour of Send code when it can be pressed. |
For signing up to an app, logging in with an SMS code, a shop checkout asking for a delivery number, booking a table or a room: anywhere an international phone number is asked for.
The same field, as wide as the screen minus the margins: the pill stays 52 pixels tall, the country menu opens under the tag and stays inside the screen. Tapping the field opens the number pad (inputmode tel) and tapping the tag opens the menu; pasting a number with a plus switches country here too.
No fake pointer, no springs or slides: the digits fade in in place, the field does not shake but turns red, the code changes without rolling and the button goes from Send code to Code sent with a fade.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 9.0 KB; the libraries: GSAP 28 KB.
Tested on 25 October 2026
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.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.