Skip to content
animorio
IT
All components

Country select dropdown

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

The country select dropdown of a made-up shop’s shipping address form, clean and premium on white: on click the field itself becomes the list and grows downward with staggered options; inside there is a small search, and as you type the options that do not match close on a spring while the matching letters light up. A pill follows the active option with the mouse and the arrow keys, choosing folds the list back into the field, the new country rises in place of the old one and the phone code below rolls digit by digit.

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>
<!--
  "Country select dropdown" 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 country select dropdown with the search that closes the options</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 Country select of a made-up shop's shipping address form: the field opens into its own list, a small search
         inside closes the countries that do not match on a spring, a pill follows the active one, and the phone code
         below rolls to the chosen country -->
    <form class="wrap" data-wrap autocomplete="off" onsubmit="return false">
      <p class="head"><span class="head__brand">Ivelle</span><span class="head__sep" aria-hidden="true"></span><span class="head__title">Shipping address</span></p>

      <div class="slot">
        <div class="box" data-box>
          <button class="field" type="button" data-field role="combobox" aria-haspopup="listbox" aria-expanded="false"
                  aria-controls="country-list" aria-labelledby="country-label country-value">
            <span class="field__label" id="country-label">Country</span>
            <span class="field__val" id="country-value" data-val></span>
            <svg class="field__chev" data-chev viewBox="0 0 24 24" aria-hidden="true"><path d="M7 10l5 5 5-5"></path></svg>
          </button>

          <div class="body" data-body hidden>
            <span class="body__rule" data-rule aria-hidden="true"></span>
            <label class="search" data-search>
              <svg class="search__ic" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="6.2"></circle><path d="M15.6 15.6 19.6 19.6"></path></svg>
              <input class="search__in" data-input type="text" role="combobox" aria-autocomplete="list" aria-expanded="true"
                     aria-controls="country-list" aria-label="Search countries" placeholder="Search countries" spellcheck="false">
              <button class="search__clear" type="button" data-clear aria-label="Clear the search" tabindex="-1">
                <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8 8l8 8M16 8l-8 8"></path></svg>
              </button>
            </label>
            <div class="list" data-scroll>
              <ul class="list__ul" id="country-list" role="listbox" aria-label="Countries" data-list>
                <li class="hl" data-hl aria-hidden="true"></li>
              </ul>
              <p class="empty" data-empty aria-hidden="true">No country matches</p>
            </div>
          </div>
        </div>
      </div>

      <div class="phone">
        <span class="phone__label" id="phone-label">Phone</span>
        <span class="phone__row">
          <span class="dial" data-dial aria-hidden="true"></span>
          <span class="phone__rule" aria-hidden="true"></span>
          <input class="phone__in" type="tel" inputmode="tel" aria-labelledby="phone-label" data-dialsr placeholder="Mobile number">
        </span>
      </div>

      <div class="key" data-key aria-hidden="true">
        <svg class="key__arrow" data-keyarrow viewBox="0 0 24 24"><path d="M12 6v12M7 13l5 5 5-5"></path></svg>
        <span class="key__word" data-keyword>Enter</span>
      </div>
      <p class="sr" data-live aria-live="polite"></p>
    </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>

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.

22 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 “Country select dropdown” 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 piece of an address form: on top the Ivelle brand and Shipping address, then the Country field with the chosen country, United Kingdom, after its code GB in a black round, and below it the Phone field with the +44 code. The fields have a barely grey fill, a one pixel border and a thin light along the top edge; on hover the field turns white and its border darkens. Pressed, the field squeezes slightly and springs back, then becomes the list itself: the border stretches downward with a small run, a soft layered shadow appears, the chevron turns with a bounce, a thin rule opens from the middle, the search comes in and the options drop one after another, each with its code in a grey round, its name and its phone code. A grey pill sits under the active option and glides after it on a spring, with the mouse and with the arrow keys, and the list scrolls by itself to keep it in view; the chosen country has a blue check. Typing in the search, the options that do not match fade and close in height, the others move up to fill the gap and the matching letters turn blue on a soft tint; a clear button appears, and when nothing is left the row says No country matches. Choosing, the options leave in a row, the list folds back into the field, which settles with a one pixel dip; the old country leaves upward and the new one rises from below with its code turning, while the phone code rolls digit by digit and its space widens or narrows. A drawn pointer opens it, types it, picks Italy, then opens it again and reaches Japan with the arrow keys, showing the pressed key at the top right.

How it works

One box for field and list

The field and the list live in the same absolutely positioned box inside a slot as tall as the field: on opening the list part shows, the full height is measured and GSAP takes the height from the field’s to the full one with back.out, then frees it. So the field’s border becomes the list’s border and the box passes over the phone field.

Options that close on a spring

Each option is an li with overflow hidden: the ones that do not match lose their content first (fade and scale 0.94) and then their height down to zero, and finally get the hidden attribute; the ones that come back grow to one row with back.out. The name is rewritten with a mark around the matching letters.

The pill of the active option

One absolute element inside the list goes to the active option’s offsetTop on a spring; while options close, the filter timeline places it on every frame, so it never sits on an empty row. The list scrolls through its scrollTop to keep the option in view.

Really accessible

The field is a button with role combobox and aria-expanded; the search is a combobox input that points to the listbox and announces the active option with aria-activedescendant. Arrows, Home, End, Page Up and Down, Enter to choose, Esc to clear the search and then close; an aria-live region says how many countries are left and the new phone code.

The value and the code that roll

The old value leaves upward and the new one enters from below in a 22 pixel window with back.out, which lands it a pixel too far and brings it back; the phone code is split into digits that rise staggered, while its width goes to the measured width of the new text.

Values to change

NameFileDefaultWhat it changes
STARTscript.jsGBThe code of the country chosen at the start.
ACCENTscript.js#3f4fe8The colour of the matching letters, the check and the focus border.
ROWSscript.js4.5How many options show in the open list before it scrolls.
OPEN_TIMEscript.js0.55How many seconds the spring that opens the list from the field lasts.
PILL_SPRINGscript.js1.5How much the pill following the active option bounces.
STAGGERscript.js0.028The stagger between one option and the next as the list opens.
TYPE_PAUSEscript.js0.38The seconds between the letters typed by the drawn pointer.

Try them in the Playground

When to use it

In an online shop’s checkout, in a shipping or billing address form, in an app’s sign up or a user profile: wherever a country is picked from a long list and the phone code has to follow it.

On phones

The form narrows to the screen width, fields and rows are sized on the height too and the open list stays inside the room kept under the field; a finger opens, scrolls the list and chooses like the mouse, and the pill goes to the tapped option.

With reduced motion

No springs or movement: the list fades in and out, filtered options disappear at once, the pill jumps to the active option and the new value and phone code fade in; the drawn pointer is not shown.

Pitfalls

  • The open height spring was written with overwrite: true and also killed the press’s elastic return on the box, which stayed shrunk and showed the phone field’s edges below: without the overwrite the two tweens live together.
  • The key pressed by the drawn pointer was centred at the bottom with translateX(-50%), but GSAP’s inline transform wiped it: it now sits at the top right, with no transform in the CSS.
  • While options close, the active one moves on every frame: the pill is placed again in the filter timeline’s onUpdate, otherwise it stayed on a row that no longer exists.
  • Keeping the box height fixed after opening made a resize cut it: at the end of the spring the height is freed (clearProps) and the list follows the closing options on its own.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 13 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