Skip to content
animorio
IT
Back to the library

Pattern lock

SVG, HoverGSAPMediumCompressed weight: Demo 7.3 KBGSAP 28 KBFreeDownload the zip

The sign-in card of a made-up notes app, Keel: you unlock it by drawing a pattern across nine dots. The line starts on the first dot, follows your finger like a stretched band and snaps to every dot it crosses, which swells on a spring; a dot skipped in the middle is taken on its own. A wrong pattern turns soft red, the grid shakes two pixels, the tries counter rolls and the line pulls back; the right one lights up blue, the dots gather to the centre, the lock opens and the card says «Welcome back». Minimal style, a single accent.

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>
<!--
  "Pattern lock" 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>Pattern lock</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>
  <!-- The pattern unlock of a made-up notes app, Keel. Drag across the nine dots: the line starts on the first dot,
       follows the pointer like a stretched band and snaps to every dot it crosses (a dot skipped in the middle is taken
       on its own, like on a phone). Let go: a wrong pattern turns soft red, the grid shakes and the line pulls back;
       the right one lights up, the dots gather to the centre, the lock opens and the card says welcome back. -->
  <main class="stage">
    <section class="card" data-card aria-label="Keel, unlock with your pattern">
      <header class="card__top">
        <svg class="lock" data-lock viewBox="0 0 24 24" aria-hidden="true">
          <path class="lock__shackle" data-shackle d="M8 11V8.2a4 4 0 0 1 8 0V11"/>
          <rect class="lock__body" x="5.5" y="11" width="13" height="9.5" rx="2.6"/>
          <path class="lock__hole" d="M12 14.6v2.2"/>
        </svg>
      </header>

      <div class="views">
        <div class="view view--lock" data-view-lock>
          <h1 class="title">Draw your pattern</h1>
          <p class="hint" aria-live="polite">
            <span class="hint__msg" data-msg>to unlock Keel</span>
          </p>
          <div class="pad" data-pad>
            <svg class="grid" data-grid viewBox="0 0 300 300" role="img" aria-label="Nine dots to connect">
              <g data-shadows></g>
              <path class="trail" data-trail d=""/>
              <g data-dots></g>
            </svg>
          </div>
          <p class="tries"><span class="tries__slot"><span class="tries__col" data-col><span>3</span><span>2</span><span>1</span><span>3</span></span></span><span class="tries__label">tries left</span></p>
        </div>

        <div class="view view--hello" data-view-hello aria-hidden="true">
          <span class="avatar" data-avatar><span class="avatar__text">MR</span></span>
          <h2 class="hello" data-hello>Welcome back, Mara</h2>
          <p class="meta" data-meta>Keel · 14 notes since Friday</p>
        </div>
      </div>
    </section>
    <svg class="pointer" data-pointer viewBox="0 0 20 20" aria-hidden="true"><path d="M4 2.5v13.2l3.6-3.4 2.4 5.4 2.3-1-2.4-5.3 5-.3z"/></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.

25 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 “Pattern lock” 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 a warm white background, a white card with a small padlock at the top, the title «Draw your pattern», the line «to unlock Keel», nine grey dots in a grid and «3 tries left» below. Drag from the first dot: the dark line starts there and follows the pointer like a stretched band, and every dot it meets swells on a spring, turns dark and takes a thin ring and a soft shadow; go from one corner to the other and the dot in the middle is taken on its own, like on a phone. The longer the line, the thinner it gets. Let go: if the pattern is wrong the line and the dots turn soft red, the grid shakes two pixels, the line reads «Wrong pattern, 2 tries left» and the tries number rolls; then the line pulls back from its end and the dots go dark one by one. If it is right, the line lights up blue, the dots gather to the centre one after another and vanish, the padlock lifts and swings open, and the card shows the blue avatar with initials, «Welcome back, Mara» and how many notes there are since Friday. After a pause the padlock closes again and the grid comes back. On its own a pointer draws a wrong L first and then the right Z.

How it works

Dots in a 300 grid

The grid is an SVG with a 300 by 300 viewBox and the nine dots at 50, 150 and 250: everything is computed in those units, so the pointer is brought into the grid by dividing by its real width, and the demo holds at any size.

The line that follows your finger

The line is a single path rebuilt on every move: the dots taken plus the tail to the pointer. A dot is taken when the pointer passes within SNAP of it; the thickness goes from LINE_THICK to LINE_THIN as the line gets longer.

The skipped dot

Between the last dot and the new one, if row and column are both an even distance apart, there is a dot in the middle: it is taken first, like on a phone, and the pattern stays the one the finger really drew.

Wrong or right

On release the pattern is compared with PATTERN. Wrong: soft red, ±SHAKE pixel keyframes on the grid and the line pulling back through a tween on the shown fraction, switching off the dots it uncovers. Right: every dot flies to the centre with the line following, then the padlock swings around its right post with svgOrigin and the card changes view.

Values to change

NameFileDefaultWhat it changes
PATTERNscript.js"0-1-2-4-6-7-8"The right pattern, dots counted from the top left (this one is a Z).
SNAPscript.js36How close the pointer must pass to take a dot, on a 300 grid.
LINE_THICKscript.js8The line thickness when it is short.
LINE_THINscript.js4.5The line thickness once it has crossed the whole grid.
SHAKEscript.js2How many pixels the grid shakes when the pattern is wrong.
HOLDscript.js2.8How many seconds the welcome stays before the lock comes back.
AUTOPLAYscript.jstrueA pointer draws a wrong pattern and then the right one on its own, until you draw.
--accentstyle.css#2f6df6The colour of the right pattern and of the avatar.
--wrongstyle.css#e2564fThe soft red of the wrong pattern.

Try them in the Playground

When to use it

On the lock screen of a notes app, a journal, a bank or a wallet, as an alternative to a passcode; on an app’s page to show sign-in with a gesture; anywhere a login faster than a password is needed.

On phones

The card and the grid are sized on width and height (min of vw and vh, with clamp), so they fit whole in the phone box; the finger draws the pattern as on a real phone, and the page does not scroll while you drag (touch-action: none).

With reduced motion

No springs, shakes or flights: the dots switch on and off without swelling, the line appears whole, the grid does not shake and the card fades to the welcome; the automatic pointer is not shown.

Pitfalls

  • The padlock swings around the right post of the shackle: svgOrigin applies to the path inside the svg, not to the svg itself.
  • The pointer is brought into the grid by dividing by the svg’s real width: the grid changes size with the window.
  • With setPointerCapture the line keeps following the finger even outside the grid, and the release always arrives.
  • While the wrong line pulls back the grid ignores a new touch, otherwise two patterns would mix.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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