Skip to content
animorio
IT
All components

Alignment toolbar

Drawing, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.5 KBGSAP 28 KBFreeDownload the zip

The alignment bar of a design tool, on white: above, an artboard with three objects inside the selection box; below, the buttons to align left, centre, right, top, middle, bottom and to distribute the spacing. On every click the objects go to their place on a spring, the box follows them and a guide flashes on the chosen edge.

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>
<!--
  "Alignment 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>Alignment toolbar</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 alignment bar of a design tool: three objects on an artboard line up or spread out on a spring,
         the selection box follows them and a guide flashes on the edge they were aligned to -->
    <section class="al" data-al aria-label="Alignment">
      <div class="al__board" data-board aria-hidden="true">
        <span class="al__guide" data-guide></span>
        <span class="al__obj al__obj--a" data-obj><i></i></span>
        <span class="al__obj al__obj--b" data-obj><i></i></span>
        <span class="al__obj al__obj--c" data-obj><i></i></span>
        <span class="al__box" data-box><b></b><b></b><b></b><b></b></span>
      </div>
      <div class="al__bar" role="toolbar" aria-label="Align and distribute">
        <button class="al__btn" type="button" aria-label="Align left" data-do="left"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2.500 2v12"></path><rect x="5.000" y="3.500" width="8.000" height="3.200" rx="1"></rect><rect x="5.000" y="9.300" width="5.000" height="3.200" rx="1"></rect></svg></button>
        <button class="al__btn" type="button" aria-label="Align horizontal centres" data-do="hcenter"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 2v12"></path><rect x="3.000" y="3.500" width="10.000" height="3.200" rx="1"></rect><rect x="5.000" y="9.300" width="6.000" height="3.200" rx="1"></rect></svg></button>
        <button class="al__btn" type="button" aria-label="Align right" data-do="right"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M13.500 2v12"></path><rect x="3.000" y="3.500" width="8.000" height="3.200" rx="1"></rect><rect x="6.000" y="9.300" width="5.000" height="3.200" rx="1"></rect></svg></button>
        <span class="al__sep" aria-hidden="true"></span>
        <button class="al__btn" type="button" aria-label="Align top" data-do="top"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 2.500h12"></path><rect x="3.500" y="5.000" width="3.200" height="8.000" rx="1"></rect><rect x="9.300" y="5.000" width="3.200" height="5.000" rx="1"></rect></svg></button>
        <button class="al__btn" type="button" aria-label="Align vertical centres" data-do="vmiddle"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 8h12"></path><rect x="3.500" y="3.000" width="3.200" height="10.000" rx="1"></rect><rect x="9.300" y="5.000" width="3.200" height="6.000" rx="1"></rect></svg></button>
        <button class="al__btn" type="button" aria-label="Align bottom" data-do="bottom"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 13.500h12"></path><rect x="3.500" y="3.000" width="3.200" height="8.000" rx="1"></rect><rect x="9.300" y="6.000" width="3.200" height="5.000" rx="1"></rect></svg></button>
        <span class="al__sep" aria-hidden="true"></span>
        <button class="al__btn" type="button" aria-label="Distribute horizontal spacing" data-do="disth"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2.500 2v12M13.500 2v12"></path><rect x="6.400" y="4.000" width="3.200" height="8.000" rx="1"></rect></svg></button>
        <button class="al__btn" type="button" aria-label="Distribute vertical spacing" data-do="distv"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 2.500h12M2 13.500h12"></path><rect x="4.000" y="6.400" width="8.000" height="3.200" rx="1"></rect></svg></button>
        <span class="al__sep" aria-hidden="true"></span>
        <button class="al__btn al__btn--mix" type="button" aria-label="Scatter the objects" data-mix><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 4.500h2.500c3.500 0 3.500 7 7 7H14M2 11.500h2.500c1.200 0 2-.800 2.700-1.900M14 4.500h-2.500c-1.200 0-2 .800-2.700 1.900M12 2.500l2 2-2 2M12 9.500l2 2-2 2"></path></svg></button>
      </div>
      <p class="al__note" aria-live="polite"><span data-say>Three objects selected</span></p>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></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.

11 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

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 “Alignment 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

On white: a pale grey artboard with a faint grid and three scattered objects, a blue rectangle, a taller dark one and a light blue circle, enclosed in a blue selection box with its four handles. Below, a white bar with nine icon buttons split by three small rules: align left, centre, right; top, middle, bottom; distribute horizontally and vertically; and, for the demo, scatter. On click the button lights up blue and gives a little, the three objects set off one after the other and reach their place with a small bounce, the selection box tightens around them and a pink guide draws itself for a moment on the edge or the centre they were aligned to. With the two distribute buttons the objects stay between the first and the last and take equal gaps. Under the bar a line says what just happened, “Aligned bottom”, “Spaced evenly across”, and rolls at every action. Scatter spreads them over the artboard again.

How it works

The objects are numbers

Each object has x, y, width and height in a list; the buttons only change those numbers, then one function draws them.

Aligning

The box that contains them all is computed and each one’s edge, or centre, is brought onto the box’s: the align-to-selection of design tools.

Distributing

They are sorted by position, the sum of the widths is taken from the box’s width and the room left is split into equal parts.

The motion

Each object goes to its new numbers on a spring with a small delay; the selection box animates position and size, the guide scales from zero and fades.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#2f7df6The colour of the selection, of the used button and of the first object.
GUIDEscript.js#ff3d8bThe colour of the guide that flashes on the alignment edge.
STAGGERscript.js0.05The delay between one object and the next when they move.
SPRINGscript.js1How much the objects bounce: 0.3 = a little, 2 = a lot.
LOOPscript.jstrueLeft alone, the demo’s pointer aligns, distributes and scatters.

Try them in the Playground

When to use it

In tools where things are arranged on a surface: graphic and presentation editors, page builders, whiteboards, floor plans, email editors. Also on a design tool’s site, to show the feature.

On phones

The same thing, 296 pixels wide at most: the artboard takes the width there is and stays 168 pixels tall at most, the nine buttons fit on one row and are 29 pixels wide each.

With reduced motion

The objects and the selection box go straight to the new position, without the spring; the guide appears whole and fades. The demo does not move by itself.

Pitfalls

  • Aligning left and then top puts the objects on top of each other: real tools do the same, and that is why the demo has the button that scatters them.
  • Distributing objects wider than the room there is makes the gap negative and they overlap by equal parts.
  • The positions are in the artboard’s pixels: on resize they are kept inside the edges and redrawn at once.
  • The artboard is only to look at (aria-hidden): each button has its own label and the line under the bar, with aria-live, says what just happened.
  • The used button stays lit until another is pressed: in a real app it usually does not, because the action is already done.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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