Skip to content
animorio
IT
All components

Floating label field

Forms, HoverGSAPMediumCompressed weight: Demo 4.2 KBGSAP 28 KBFreeDownload the zip

A text field with one gesture, as simple as the seal logo: tapping it, the label rises onto the border, shrinks and takes weight, and the top line opens for it from the middle, its two ends passing their mark by a pixel and settling. Left empty, the label drops back and the border closes behind it.

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>
<!--
  "Floating label 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 field whose label settles into the border</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 text field: on focus the label rises and the top border opens for it from the middle outwards -->
    <div class="field" data-field>
      <svg class="field__line" data-svg aria-hidden="true"><path data-border /></svg>
      <label class="field__label" for="email" data-label><span data-label-text>Email</span></label>
      <input class="field__input" id="email" type="email" autocomplete="off" spellcheck="false" data-input data-autoclic>
      <p class="field__help" data-help>Only for your receipts.</p>
    </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.

14 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 “Floating label 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

On white there is a single text field with a thin grey outline and rounded corners, and inside it, large and light, the word Email. Tapping it, the label rises to the top line, grows small, takes weight, widens a little and turns orange; meanwhile the line opens for it from the middle of the word: the two cut ends move apart, pass their mark by a pixel and come back, and the outline turns orange and a touch thicker. Under it shows Only for your receipts. Leaving the field empty, the label drops back to its place and the border closes behind it, the two ends meeting with the same small spring; leaving it filled, the label stays in the border and turns grey again. On its own, until someone touches it, the field types an address with a drawn caret, deletes it and closes again.

How it works

The border is a single line

The outline is an SVG path that starts at one side of the gap, runs all the way round with rounded corners and ends at the other side. The gap is centred on the centre of the label once it has settled (measured once at its final weight and width, then shrunk) and widens with the gap value from 0 to 1: on every frame the path is rewritten with its two ends in the right place.

One object, three numbers

How far the label has risen, how open the gap is and how much accent is on sit in one object GSAP animates. The label rises by half the height and goes from 17 to 12 pixels with a scale, from weight 400 to 560 and width 100 to 112 on Mona Sans’s axes; the gap starts a moment later, so it seems to open for it. Both with back.out: the extra pixel and the settle are BOUNCE.

Empty or filled

On leaving, if the field is empty, the label drops back and the gap closes a moment later, the two ends meeting with the same spring; if it is filled, the label stays in the border and only turns grey. The colour of the line and the label comes from gsap.utils.interpolate between the colours in :root.

The preview that types on its own

Until someone touches it, a GSAP timeline opens the field, types EXAMPLE one letter at a time with a drawn caret (measured on a hidden twin of the text), deletes it and closes it, without ever taking the real focus. The first real touch stops it and the field goes back to being a field.

Values to change

NameFileDefaultWhat it changes
LABELscript.js'Email'The label of the field.
EXAMPLEscript.js'ada@harlow.studio'What the preview types on its own.
HELPscript.js'Only for your receipts.'The line under the field while it is in use ('' = none).
LIFTscript.js0.5How long the label takes to rise, in seconds.
OPENscript.js0.55How long the border takes to open, in seconds.
BOUNCEscript.js1.6How far the label and the ends pass their mark: 0 none, 3 a lot.
AUTOscript.jstrueThe preview types and clears on its own until someone touches it.
--accentostyle.css#e8590cThe colour of the field in use.

Try them in the Playground

When to use it

For any form that wants a clean field with the label always in sight: sign-ups, log-ins, payments, contact forms. The border opening tells you where you are without adding anything.

On phones

The field widens to 86% of the screen (at most 340 pixels) and the gap is measured again whenever the size changes; the rest is the same.

With reduced motion

The label and the border change state without motion, the help line fades in and the preview does not type on its own.

Pitfalls

  • The gap’s width is measured on the label at its final weight and width, not at rest: measured at rest the gap would be too narrow and the line would cut through the letters.
  • The preview never calls focus(): on a page with several demos it would steal the keyboard from the page; the caret is drawn.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 4.2 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