vangle

2026-10-19

Back in 2011 Bret Victor released Tangle, a small library for "reactive documents". The idea is that you can drag a number in a paragraph and watch the rest of the text update with it. I've always loved that idea, so I made a modern take on it called vangle.

It's one ES module and one stylesheet. There is no build step and there are no dependencies. You write plain HTML with a few custom elements, and you never write an update() function because a small signals core recomputes everything for you.

It is great for small explainers on a simple static blog like mine, but it also turns out to be "just enough" to make an HTML explainer feel less like slop. Something about defining the building blocks and pointing an agent at it makes the final artifact a lot more fun to play with.

Basic Example

When you eat 3 cookies, you consume calories. That's % of a 2000 calorie diet.

That's the classic Tangle example, and this is all the HTML it takes:

<p>When you eat <t-num name="cookies" min="0" max="20">3</t-num> cookies,
   you consume <t-out expr="calories"></t-out> calories.</p>
<t-let name="calories" expr="cookies * 50"></t-let>

A <t-num> is a draggable number, a <t-let> is a computed value and a <t-out> shows the result of an expression. The text inside the <t-num> is its starting value, which is also what you see without JavaScript, so an RSS reader still gets a sensible sentence.

Click to choose

Not everything is a number. A <t-choice> cycles through options when you click it.

Saving 200 euro per month adds up to euro a year.

<t-choice name="per" options="per week:52, per month:12, per year:1">per month</t-choice>

Formulas you can drag

This is the part I'm most excited about. A <t-math> is a KaTeX formula with live markers in it. \tangle{r} shows a variable that you can drag, and \val{...} shows a computed result. The chart underneath reads the same variables, so it grows along with the formula.

\tangle{P} \cdot \left(1 + \frac{\tangle{r}}{100}\right)^{\tangle{t}} = \val[%,.2f]{P * (1 + r / 100) ** t}
<t-var name="P" value="1000" min="0" max="10000" step="100" format="%,d"></t-var>
<t-var name="r" value="5" min="0" max="15" step="0.5"></t-var>
<t-var name="t" value="10" min="1" max="40"></t-var>
<t-math display>
  \tangle{P} \cdot \left(1 + \frac{\tangle{r}}{100}\right)^{\tangle{t}}
    = \val[%,.2f]{P * (1 + r / 100) ** t}
</t-math>

The chart is a <t-vega> with a Vega-Lite spec inside. Its data source is called growth, and so is a <t-let> that computes one row per year, which is all it takes to link them.

Formulas also work inline. A pendulum of length 1 swings with a period of .

Everything is connected

A variable can show up in as many places as you like, and they all stay in sync. Below, a, b and c appear in the formula, in the sentence, in the roots and in the chart. Drag any of them, anywhere, and watch the rest follow. The letters in the formula turn into numbers while you drag them.

f(x) = \tangle[a]{a}\,x^2 + \tangle[b]{b}\,x + \tangle[c]{c}

With , and the parabola opens and has .

x = \frac{-(\tangle{b}) \pm \sqrt{\val[%.2f]{disc}}}{2 \cdot \tangle{a}} \quad\Rightarrow\quad x_1 = \val[%.2f]{(-b - Math.sqrt(disc)) / (2 * a)}, \; x_2 = \val[%.2f]{(-b + Math.sqrt(disc)) / (2 * a)}

There's no glue code here. The chart is a <t-obsplot> holding an Observable Plot expression that reads a, b, c and roots, and vangle redraws it whenever one of them changes:

<t-obsplot>
  <script type="text/plain">
  {
    y: { domain: [-8, 8], grid: true },
    marks: [
      Plot.line(d3.range(-5, 5.001, 0.05), {
        x: (x) => x,
        y: (x) => a * x * x + b * x + c
      }),
      Plot.dot(roots, { x: (x) => x, y: 0 })
    ]
  }
  </script>
</t-obsplot>

Only what changed recomputes

A change doesn't redraw the whole page. Each value remembers which variables it read, and only the values that read a changed variable run again. To make that visible, the two values below go through a small count function that keeps a tally of how often each one runs.

1 + 2 = , which ran

× 3 = , which ran

Some things to try:

  • Change c. Only product runs. sum doesn't read c, so its tally stays put.
  • Change a or b. Both run, because sum reads them and product reads sum.
  • Count the reads. sum is shown twice and read by product, yet it runs once per change. The first read computes it and the others get the cached value.

The count function is the only JavaScript on this page. It's a registered function, which is how you hand your own JavaScript to vangle's expressions:

<script type="module">
import { registerFunction, scopeOf } from "tangle.js";

const scope = scopeOf(document.querySelector("#recompute"));
registerFunction("count", (name, value) => {
  scope.set(`${name}Runs`, (scope.peek(`${name}Runs`) ?? 0) + 1);
  return value;
});
</script>

Using it

To learn more, you can check the docs. It's designed to be agent friendly and I have found it to be a missing piece to write good html explainers.