Skip to content
animorio
IT
All components

Search field with lens

Search, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.1 KBGSAP 28 KBFreeDownload the zip

One sign does everything: on white there is only a lens; on tap a thin line stretches out on both sides and becomes the field, the lens slides to the end and there its handle runs through it, the ring winds itself closed and a second stroke draws across: it has become the cross that clears the field. The search types itself, three results rise below in thin staggered rows, and the cross folds everything back into the lens.

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>
<!--
  "Search field with lens" 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 search field with the lens that turns into the cross</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" data-stage>
    <!-- one sign: the lens stretches into a field, and its handle and its ring become the cross that clears it -->
    <div class="find" data-find>
      <div class="find__field" data-field>
        <span class="find__line" data-line aria-hidden="true"></span>
        <label class="find__box" data-box>
          <span class="visually-hidden">Search the shop</span>
          <input class="find__input" data-input type="search" autocomplete="off" spellcheck="false" placeholder="Search" tabindex="-1" aria-controls="find-list">
        </label>
        <button class="find__sign" data-sign type="button" aria-label="Search" aria-expanded="false">
          <span class="find__sign-in" data-sign-in>
            <svg viewBox="0 0 24 24" aria-hidden="true">
              <circle class="find__ring" data-ring cx="10.5" cy="10.5" r="5.6"/>
              <line class="find__stroke" data-handle x1="14.6" y1="14.6" x2="19" y2="19"/>
              <line class="find__stroke" data-cross x1="18" y1="6" x2="6" y2="18"/>
            </svg>
          </span>
        </button>
      </div>
      <ul class="find__list" id="find-list" data-list role="listbox" aria-label="Results"></ul>
    </div>
  </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.

39 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 “Search field with lens” 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, alone in the middle, there is a lens drawn in two thin strokes: a ring and the handle. Hovering tilts it a little and brings it closer. On tap it gives and springs back, and a one-pixel black line stretches from the middle towards both sides: it is the edge of the field. The lens rides it to the far right and there it changes: the handle slides and runs right through it from corner to corner, the ring winds itself closed until it vanishes, a second stroke draws across and the sign turns a quarter with a hair of bounce: now it is the cross that clears the field. In the field the word Search appears in grey with a blinking blue caret; the search types itself, a letter at a time, «linen shirt». From the second letter three results rise below, one row after the other, each with a thin rule drawing from the left and the price arriving last; the letters found in the name are blue, and they light up further as the typing goes on. The whole block rises as much as needed to keep field and results centred. Tapping the cross sends the rows away, the cross folds back into the lens, the line draws in towards the middle and the lone lens is back. You can really type, Enter picks the first result, Escape closes it. Until someone touches it, the search plays the gesture by itself.

How it works

A single number

Open or closed is a number from 0 to 1: place() uses it for the scale of the line, which stretches from the middle, and for the travel of the lens, which starts in the middle and ends at the far right. The same number recomputes everything on resize, even halfway through opening.

The lens turning into the cross

The sign is an SVG of three strokes: the ring, the handle and the cross’s second stroke. The handle stretches its ends to the two corners, the ring winds closed with strokeDashoffset while shrinking to the centre, the second stroke draws, and the group turns 90 degrees with back.out: that is the settle. On the way back the same in reverse, with the second stroke leaving from the far end.

The result rows

search() keeps the products containing every word typed, SHOWN at most; lit() wraps the letters found in a b. If the list does not change only the lit letters update, without restarting the rows; if it does, the old ones leave and the new ones rise staggered, with the thin rule and the price a moment later.

The caret

The field’s own caret is transparent and a blue line takes its place: a hidden span in the same font measures the text typed and the line slides behind it, so it shows even while the search types itself.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#2f5bffThe colour of the caret and of the letters found.
QUERYscript.jslinen shirtWhat the search types by itself.
PLACEHOLDERscript.jsSearchThe word in the empty field.
SHOWNscript.js3How many results at most.
SPRINGscript.js1How springy the sign and the rows are: 0.4 calm, 2 very bouncy.
SPEEDscript.js1The speed of everything: 2 twice as fast, 0.5 half.
HOLDscript.js2.4How many seconds the results stay when the search plays by itself.
AUTOscript.jstrueThe search plays the gesture by itself until someone touches it.

Try them in the Playground

When to use it

For the search of an online shop, a blog or an app that should stay folded into an icon until it is needed: the same icon is also the button that clears and closes it, with no second sign to look for.

On phones

On the phone the field takes the full width minus the margins and the text sizes follow the shorter side; there is no hover, everything else is the same.

With reduced motion

The line, the lens, the cross and the rows appear and disappear with a fade, with no springs or movement.

Pitfalls

  • The closed lens sits in the middle, the open one at the far right: the travel must be computed from the field’s real width on every resize, or on the phone the closed lens stays off centre.
  • If the list of results is the same as before, the rows must not be rebuilt: only the lit letters change, otherwise every letter typed would restart the rows.
  • The ring closing and the cross’s second stroke use strokeDasharray: it is set in the script with the computed length, because the CSS cannot know how long a ring that changes radius is.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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