Skip to content
animorio
IT
All components

Code block with diff

Code, Text, TransitionsGSAP, CSS onlyMediumCompressed weight: Demo 10 KBGSAP 28 KBFreeDownload the zip

The code block of a suggested change in Tessel, a made-up developer app, on black: a TypeScript file in a diff view, with the removed lines in red and struck through by a thin line and the added ones in green. Pressing Apply suggestion folds the removed lines away one after another like an accordion, the added ones slide up into their place and lose their colour, the line numbers roll to their new values while a thread of light runs down the margin, the +3 −2 count goes to zero and the button draws the Applied tick. Undo brings it all back as it was.

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>
<!--
  "Code block with diff" 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 code block with the diff that applies line by line</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- a suggested change in a code review of Tessel, a made-up tool for developers: the diff with the removed lines
         (red, struck through with a thin line) and the added ones (green). Apply suggestion folds the removed lines
         away one after another, the added ones slide into their place and lose their colour, the line numbers roll
         to their new values, a thread of light runs down the margin and the +3 -2 count goes to zero. Undo brings
         it all back. -->
    <section class="sug" aria-label="Tessel code review: suggested change in src/cart/price.ts" data-sug>
      <span class="sug__glow" aria-hidden="true" data-glow></span>
      <header class="sug__head">
        <span class="sug__avatar" aria-hidden="true">MK</span>
        <p class="sug__who"><b>Mira Kovac</b> <span>suggested a change</span></p>
        <span class="sug__count" data-count aria-label="3 lines added, 2 removed">
          <span class="sug__plus">+<span class="roll" data-roll="add">3</span></span>
          <span class="sug__minus"><svg viewBox="0 0 8 8" aria-hidden="true"><path d="M1.2 4h5.6"/></svg><span class="roll" data-roll="del">2</span></span>
        </span>
      </header>
      <div class="sug__file">
        <svg class="sug__file-icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.8h5.2L12.6 5.2v9H4z"/><path d="M9 1.8v3.6h3.6"/></svg>
        <span class="sug__path"><span>src/cart/</span>price.ts</span>
        <span class="sug__state roll" data-state><span>Suggestion</span></span>
      </div>
      <div class="code" data-code>
        <span class="code__thread" aria-hidden="true"><span class="code__beam" data-beam></span></span>
        <div class="code__rows" data-rows></div>
      </div>
      <footer class="sug__foot">
        <button class="btn btn--ghost" type="button" data-undo aria-hidden="true" tabindex="-1">
          <svg class="btn__icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M5.6 3.4L2.6 6.4l3 3"/><path d="M2.8 6.4h6.4a3.8 3.8 0 0 1 0 7.6H6.6"/></svg>
          <span>Undo</span>
        </button>
        <button class="btn btn--main" type="button" data-apply>
          <span class="btn__shine" aria-hidden="true" data-shine></span>
          <span class="btn__face">
            <svg class="btn__icon btn__tick" viewBox="0 0 16 16" aria-hidden="true"><path data-tick pathLength="1" d="M3.2 8.4l3.1 3.1 6.5-6.8"/></svg>
            <span class="btn__words"><span data-words>Apply suggestion</span></span>
          </span>
        </button>
      </footer>
    </section>
    <p class="sr" aria-live="polite" data-live></p>
  </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.

64 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 “Code block with diff” 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 black page sits a dark panel with round corners, a one pixel edge that catches the light on top and a soft layered shadow. At the top the avatar of Mira Kovac, with her initials on a peach and lilac gradient, the words suggested a change and on the right the count of the changes, +3 in green and −2 in red. Below, the file, src/cart/price.ts, marked Suggestion. Then the TypeScript code of a function that works out the total of a cart line, with its syntax coloured (violet keywords, blue functions, yellow types, green strings, orange numbers) and the column of line numbers on a darker ground. Two old lines, which did the sum with decimals, sit on a red wash with a minus and a thin red strike through them; three new lines, which do it in cents with the coupon discount, sit on a green wash with a plus. On arrival the panel rises a few pixels, the lines come in one after another, the washes stretch from the left and the red strikes pull across the text. Then Apply suggestion is pressed: it squashes and comes back on an elastic, a blade of light crosses it and a pale green thread of light runs down the margin between the numbers and the code. The red lines fold away one after another like the bellows of an accordion, bending from their top edge; the green lines slide up into their place one pixel too far, a light crosses them and they lose their wash and their plus. Their numbers roll in, 16, 17, 18, and the ones of the lines below roll from 18 to 22. The count becomes +0 −0 and dims, Suggestion turns into a green Applied, the button narrows, turns green and draws its tick, Undo comes in next to it and a green glow lights for a moment under the panel. Pressing Undo plays it all back: the red lines open again, the last one first, and the washes and the numbers go back as they were.

How it works

The file as data

The code is the CODE list: each entry is the kind of the line (ctx stays, del removed, add added) and its text. The script builds every row with its number column, its SVG sign, its text and its wash, and works out two numberings: the one before (kept and removed lines) and the one after (kept and added lines). Only the numbers that change roll.

Syntax colours by hand

A small tokenizer with a single regular expression splits the line into comments, strings, numbers, words, spaces and signs. A word is a keyword if it is in the list, a function if a bracket follows, a property if a dot comes before it, a type if it starts with a capital; each becomes a span with its class, and the colours live in :root.

The accordion

Each row's height is calc(1.78em * var(--o)): GSAP takes --o from 1 to 0 with power3.inOut while the content turns -82 degrees on rotateX from its top edge, inside a 300 pixel perspective, and fades. The lines below rise by themselves, and since everything is in em the size stays right when the window changes. Undo does the same backwards with back.out, the last line first.

Numbers on a drum

Every number is a window one line tall with hidden overflow: when it changes, the old figure leaves upwards (downwards going back) and the new one comes in with back.out. The same drum serves the line numbers, the +3 −2 count, Suggestion turning into Applied and the button's label, which meanwhile changes width on a spring by measuring the new word.

The thread of light and the pilot

The line between the numbers and the code holds a segment with a pale green and white gradient, clipped with clip-path so its glow spills sideways but not above or below: GSAP runs it down in BEAM seconds. A pilot made of gsap.delayedCall applies and undoes again and again and stops for good at the first real touch.

Values to change

NameFileDefaultWhat it changes
CODEscript.js[['ctx', "import { cents, dollars } from './money';"], …]The file: each row is [kind, text], with kind ctx (stays), del (removed) or add (added).
STARTscript.js12The number of the first line shown.
FOLDscript.js0.5The seconds a removed line takes to fold away.
STAGGERscript.js0.15The seconds between one removed line and the next.
ROLLscript.js0.42The seconds a number takes to roll to its new value.
BEAMscript.js1.15The seconds the thread of light takes to run down the margin.
HOLDscript.js2.6The pilot's pause between Apply and Undo.
LOOPscript.jstrueThe pilot applies and undoes again and again until someone touches the block.

Try them in the Playground

When to use it

For the code review of a developer app, an online editor or an AI coding assistant that suggests changes: it shows what changes in the file and makes clear, without a message, that the change went in and that it can be taken back. It also works on the landing page of a developer tool, as a live demonstration, or in documentation to show a migration from one version to the next.

On phones

The same animation with adapted sizes: the panel is 94% of the screen wide, the code is sized on the height too (min of vw and vh) and goes down to 9.4 pixels so the longest line fits without wrapping, the words suggested a change hide and the buttons drop to 32 pixels. A finger presses like the mouse.

With reduced motion

Nothing moves: the panel fades in, the removed lines fade out and leave the others already in their place, the washes and signs fade, the numbers, the count and the labels change with a fade, the tick appears without the button squashing, and there is no thread of light and no glow.

Pitfalls

  • A fromTo inside a timeline renders at once: the thread of light and the button's blade stayed lit between runs. They have immediateRender: false, start hidden with visibility and go out with autoAlpha.
  • The thread of light inside a margin with hidden overflow lost its glow: the margin is clipped with clip-path: inset(0 -12px), which cuts above and below but lets the light spill sideways.
  • The button's label changes width: measured with the old word still inside it gave the wrong size. The new word is measured in an invisible absolute span, the width is animated and cleared at the end (clearProps) so it stays right on resize.
  • The numbers of the added lines took the green: with the wash gone they stayed green. An is-merged class takes them back to grey with a transition.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

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

Testing

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