Skip to content
animorio
IT
All components

Tags input field

Forms, Hover, TextGSAP, CSS onlyMediumCompressed weight: Demo 5.6 KBGSAP 28 KBFreeDownload the zip

The tag field of a form: type a word and Enter closes it into a pill on a spring. Below, the suggestions starting with what you are typing light up and one tap adds them. Backspace on an empty field first marks the last tag, then removes it. Five at most: at the sixth the field says no with a shake.

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>
<!--
  "Tags input 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>Tag field with words that close into pills and suggestions</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 tag field of a publishing form: you type a word and Enter closes it into a pill on a spring; under the
         field the suggestions that match what you are typing light up and one tap adds them; Backspace on an empty
         field first marks the last tag, then removes it; five tags at most, and the field says no with a shake -->
    <section class="card" data-card>
      <div class="top">
        <label class="top__label" for="tags">Topics</label>
        <p class="top__left"><span class="top__n"><span data-left>4</span></span> left</p>
      </div>

      <div class="field" data-field>
        <ul class="tags" data-tags aria-label="Chosen topics"></ul>
        <input id="tags" class="field__input" type="text" data-input autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="Add a topic" aria-describedby="tags-hint">
      </div>
      <p class="hint" id="tags-hint"><span data-hint>Press Enter to add, Backspace to remove</span></p>

      <div class="ideas" data-ideas role="group" aria-label="Suggestions">
        <button type="button" data-idea>motion</button>
        <button type="button" data-idea>typography</button>
        <button type="button" data-idea>color</button>
        <button type="button" data-idea>layout</button>
        <button type="button" data-idea>accessibility</button>
      </div>
    </section>
    <p class="sr" data-live aria-live="polite"></p>

    <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.

20 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 “Tags input field” 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

In the middle, on white, a field labelled ‘Topics’ and, on the right, how many tags can still be added. Inside the box there is already a light violet pill, ‘design’, with its small cross, and next to it the room to type. Below, a help line and five grey suggestions. When the field is active its edge turns violet with a halo. Typing ‘mot’, the suggestion ‘motion’ lights up violet and the others step back; tapping it, the word enters the field as a pill, scaling up from small with a bounce, the count at the top rolls and the used suggestion goes dim, struck through. Typing ‘css’ and pressing Enter (or the comma) makes another pill. With Backspace on an empty field the last pill turns solid violet, to say ‘I am about to remove you’; a second Backspace makes it shrink and go, and the count goes back up. At the sixth tag the box shakes, the edge and the count turn red and the help says ‘Five topics at most’. Left alone, a pointer types, takes a suggestion, adds a tag and removes it.

How it works

A real field in a box

The box is a wrapping flex: inside are the pills and a real input, borderless, taking the room left. A click on an empty spot of the box puts the caret in the input.

From word to pill

Enter and comma call add: it strips spaces and commas, lowercases everything, rejects duplicates (the pill already there gives a nudge) and creates a list item with its cross. The pill is born at scale 0.6 and reaches 1 with elastic.out.

The suggestions

At every letter match compares the start of each suggestion with what is in the input: those that match take is-match, the others is-miss, the ones already used is-used.

Backspace in two steps

On an empty field the first Backspace marks the last pill (is-armed) and the second removes it: so a tag is not deleted by mistake when holding the key. Any other key removes the mark.

The limit

Beyond MAX tags add creates nothing: the box shakes in four steps, the edge and the count turn red for 1.8 seconds and the help line says why.

Values to change

NameFileDefaultWhat it changes
FIRSTscript.jsdesignThe tag already there at the start (empty = none).
MAXscript.js5How many tags at most.
SPRINGscript.js0.7How long the spring of the tag closing into a pill lasts, in seconds.
ACCENTscript.js#5b5bf0The colour of the tags.
TYPEscript.js0.11By itself: the seconds between one letter and the next.
PAUSEscript.js1.1By itself: the pause after each tag, in seconds.
LOOPscript.jstrueLeft alone, a pointer types, adds and removes.

Try them in the Playground

When to use it

In the form to publish an article, upload a product, open a ticket or fill in a profile: wherever a few keywords chosen by the writer are needed, with some suggestions so duplicates are not invented.

On phones

The same field, as wide as the screen: the pills wrap and so do the suggestions. On a phone keyboard the comma also closes a tag.

With reduced motion

No springs and no shake: the pills appear and go at once, the count changes without rolling and the limit is told only by colour and words.

Pitfalls

  • The box has a minimum height of two rows: without it, the card would change height at the first pill that wraps and the suggestions would run away from under the finger.
  • The demo never puts the caret in the field by itself: on a phone it would open the keyboard as soon as the page loads.
  • Each cross has its own name (‘Remove design’): with five buttons all called ‘Remove’ a screen reader would not know which tag it removes.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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