Skip to content
animorio
IT
All components

Selection toolbar

Menus, HoverGSAP, CSS onlyMediumCompressed weight: Demo 11 KBGSAP 28 KBFreeDownload the zip

The editor of a writing app on warm white: you select a sentence and the highlight grows word by word, then a dark pill toolbar springs up above it with bold, italic, link, comment and Ask AI. Bold makes the words gain weight on the wght axis, link opens a field inside the toolbar as it widens, Ask AI opens a small menu and the sentence rewrites itself out of random letters; the toolbar follows the selection and goes away when you let go.

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>
<!--
  "Selection toolbar" 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 toolbar that follows the selection</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 editor of a writing app: select some words and a dark toolbar is born above them, follows the selection
         and acts on it (bold, italic, link, comment, Ask AI) -->
    <section class="doc" data-doc aria-label="Quillary editor">
      <header class="doc__bar">
        <svg class="doc__logo" viewBox="0 0 20 20" aria-hidden="true"><path d="M4.5 15.5c3.4-.6 6.6-3 8.6-6.4l2.4-4.6-4.6 2.4C7.5 8.9 5.1 12.1 4.5 15.5Z"></path><path d="M4.5 15.5 9 11"></path></svg>
        <span class="doc__app">Quillary</span>
        <span class="doc__sep">/</span>
        <span class="doc__path">Launch notes</span>
        <span class="doc__chip" data-chip aria-hidden="true"><svg viewBox="0 0 20 20"><path d="M4.2 5.8a1.6 1.6 0 0 1 1.6-1.6h8.4a1.6 1.6 0 0 1 1.6 1.6v5.6a1.6 1.6 0 0 1-1.6 1.6H9.4l-3.4 2.8V13h-.2a1.6 1.6 0 0 1-1.6-1.6Z"></path></svg><b data-chipcount>1</b></span>
        <span class="doc__state" data-state>Saved</span>
      </header>

      <div class="doc__body" data-body>
        <h1 class="doc__title">What’s new in 3.2</h1>
        <p class="doc__p" data-text>We rebuilt the editor from the ground up. <span data-target>Every draft now syncs across your devices in under a second,</span> even on a slow train connection.</p>
        <p class="doc__p doc__p--soft" data-text>Comments stay pinned to the words they talk about, and the outline follows you as you write.</p>
        <p class="doc__meta"><span data-count>0</span> words · 1 min read</p>
        <div class="marks" data-marks aria-hidden="true"></div>
      </div>

      <div class="bar" data-bar role="toolbar" aria-label="Format selection">
        <div class="bar__shell" data-shell>
          <div class="bar__tools" data-tools>
            <button class="tool" type="button" data-act="bold" aria-label="Bold" aria-pressed="false">
              <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M6.2 4.2h4.6a3 3 0 0 1 0 6H6.2Zm0 6h5.4a3.1 3.1 0 0 1 0 6.2H6.2Z"></path></svg>
            </button>
            <button class="tool" type="button" data-act="italic" aria-label="Italic" aria-pressed="false">
              <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M8.6 4.2h6M5.4 15.8h6M11.8 4.2 8.2 15.8"></path></svg>
            </button>
            <button class="tool" type="button" data-act="link" aria-label="Link">
              <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M8.4 11.6a3 3 0 0 0 4.3 0l2.6-2.6a3 3 0 0 0-4.3-4.3l-.9.9"></path><path d="M11.6 8.4a3 3 0 0 0-4.3 0L4.7 11a3 3 0 0 0 4.3 4.3l.9-.9"></path></svg>
            </button>
            <button class="tool" type="button" data-act="comment" aria-label="Comment">
              <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M4.2 5.8a1.6 1.6 0 0 1 1.6-1.6h8.4a1.6 1.6 0 0 1 1.6 1.6v5.6a1.6 1.6 0 0 1-1.6 1.6H9.4l-3.4 2.8V13h-.2a1.6 1.6 0 0 1-1.6-1.6Z"></path></svg>
            </button>
            <span class="bar__div" aria-hidden="true"></span>
            <button class="tool tool--ai" type="button" data-act="ai" aria-label="Ask AI" aria-expanded="false">
              <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M10 3.4c.5 3.3 1.9 4.9 5.2 5.4-3.3.5-4.7 2.1-5.2 5.4-.5-3.3-1.9-4.9-5.2-5.4 3.3-.5 4.7-2.1 5.2-5.4Z"></path><path d="M15.2 13.4c.2 1.3.8 1.9 2 2.1-1.2.2-1.8.8-2 2.1-.2-1.3-.8-1.9-2-2.1 1.2-.2 1.8-.8 2-2.1Z"></path></svg>
              <span>Ask AI</span>
            </button>
          </div>
          <form class="bar__link" data-linkform autocomplete="off">
            <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M8.4 11.6a3 3 0 0 0 4.3 0l2.6-2.6a3 3 0 0 0-4.3-4.3l-.9.9"></path><path d="M11.6 8.4a3 3 0 0 0-4.3 0L4.7 11a3 3 0 0 0 4.3 4.3l.9-.9"></path></svg>
            <label class="bar__label" for="url">Link address</label>
            <input class="bar__field" id="url" type="text" data-url placeholder="Paste a link" spellcheck="false">
            <button class="bar__ok" type="submit" aria-label="Apply link">
              <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M4.8 10.4 8.3 13.8 15.2 6.4"></path></svg>
            </button>
          </form>
        </div>
        <span class="bar__nib" data-nib aria-hidden="true"></span>
      </div>

      <div class="menu" data-menu role="menu" aria-label="Ask AI">
        <button class="menu__item" type="button" role="menuitem" data-ai="improve">
          <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M4.4 15.6 12.8 7.2M11.2 5.6l3.2 3.2M15 3.6v2.2M16.1 4.7h-2.2M5.6 4.2v1.8M6.5 5.1H4.7"></path></svg>
          <span>Improve writing</span>
        </button>
        <button class="menu__item" type="button" role="menuitem" data-ai="shorten">
          <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M4 6.5h12M4 10h8M4 13.5h5"></path></svg>
          <span>Make shorter</span>
        </button>
        <button class="menu__item" type="button" role="menuitem" data-ai="translate">
          <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3.8 5.2h7M7.3 3.6v1.6M9.4 5.2c-.6 2.8-2.4 5-5 6.2M5.8 7.4c.8 1.6 2.2 2.9 4 3.7M10.6 16.4l2.7-6.6 2.7 6.6M11.6 14.2h3.4"></path></svg>
          <span>Translate to Italian</span>
        </button>
      </div>
    </section>

    <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>
    <svg class="caret" data-caret viewBox="0 0 12 24" aria-hidden="true"><path d="M3 2.5h6M3 21.5h6M6 2.5v19"></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.

35 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 “Selection toolbar” 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 of a warm white background sits a document in Quillary, an invented writing app: the top bar with the app name, the Launch notes path and the Saved status in grey, then the headline What’s new in 3.2 and two paragraphs. A drawn pointer turns into the text caret, presses at the start of a sentence and drags: the pale violet highlight grows word by word, even where the sentence wraps. When it lets go, a dark pill toolbar springs up above the sentence, its tip pointing at the middle of the line: B, I, link, comment, a thin divider and Ask AI with a drawn star and a sheen crossing it now and then. Pressing B makes the words gain weight one after the other on the wght axis of Mona Sans, lift by a pixel, and the highlight widens with them; the button stays lit. Link slides the icons away and widens the toolbar into a field: the pointer types quillary.app/sync, confirms and the words turn violet and underlined. Ask AI opens a menu under the sentence with Improve writing, Make shorter and Translate to Italian; the pointer runs over the items and picks Make shorter: the sentence rewrites itself out of random letters, the status says Writing and then Saving, the word count goes down. Finally a click elsewhere: the highlight fades, the toolbar drops and disappears, and it all starts again. It also works with a real selection, with mouse, touch and keys (Ctrl or Cmd with B, I and K, Esc to close).

How it works

Every word is a box

At start the paragraphs are split into words, each in an inline-block span, with the spaces left as text so lines wrap as before. That way GSAP can give every word its own weight and slant, and the selection is measured word by word.

A drawn highlight

The browser’s own is made transparent with ::selection: in its place there are rounded rectangles, one per line, built by joining the rectangles of the selected words that sit at the same height. As the selection grows, the last line’s rectangle stretches with a short tween; when a word changes weight it is redrawn on every frame.

A toolbar that follows

The toolbar sits above the first line, centred, and stays inside the document; if there is no room above it goes under the last line and its tip flips. It is born with back.out from a little lower and a little smaller, with the scale origin on the tip; when the selection changes it glides there on a calmer spring.

A field inside the toolbar

The icons and the link field are two layers in the same pill: on click the icons slide away, the field comes in and the pill goes from the icons’ width to the field’s with back.out, while the toolbar re-centres and the tip stays on the sentence.

A sentence that rewrites itself

Ask AI replaces the selected words with new ones; a tween from zero to one uncovers the letters from the left, and ahead of the uncovered point nine random letters change on every frame. At the end the words go from violet to the text colour, the status says Saving and the word count rolls to the new number.

Values to change

NameFileDefaultWhat it changes
LINKscript.jsquillary.app/syncThe address the autopilot types into the link field.
SHORTERscript.jsDrafts now sync in under a second,The sentence rewritten by Make shorter.
IMPROVEDscript.jsEvery draft now reaches all your devices in less than a second,The sentence rewritten by Improve writing.
ITALIANscript.jsOgni bozza ora si sincronizza sui tuoi dispositivi in meno di un secondo,The sentence rewritten by Translate to Italian.
ACCENTscript.js#5b5bd6The colour of the selection, the links and the confirm button.
BOLD_WEIGHTscript.js680The weight of bold words, on the wght axis of Mona Sans.
SPRINGscript.js1How much the toolbar bounces when it appears and moves.
PACEscript.js1The speed of the autopilot.

Try them in the Playground

When to use it

For the editor of a notes or writing app, a CMS panel, comments on a shared document, a blog with an in-browser editor, any text you select to change it or ask the AI about it.

On phones

The document narrows to the box and the text is sized on height too; the toolbar stays inside the document edges and, if there is no room above the sentence, goes underneath. The link field gets shorter under 440 pixels. With touch, the phone’s own selection brings up the toolbar just like the mouse.

With reduced motion

No springs or movement: the toolbar and the menu fade in where they belong, bold and italic change at once, the new sentence arrives with a fade instead of random letters and the drawn pointer is not shown.

Pitfalls

  • The browser’s highlight cannot be animated and jumped when the words changed weight: that is why it is drawn by hand and redrawn on every frame of the tween.
  • Pressing a toolbar button clears the selection: on the toolbar and the menu pointerdown calls preventDefault, except in the link field.
  • The autopilot’s positions are read when each step starts, with function-based values: after bold the words are wider and the link button has moved.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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