Gradient Decent / no-js

Can a page with no script write by itself?

The style engine as a whole computer. The same tiny Shakespeare model as the css page, with the last of the JavaScript taken out: the clock, the memory, the maths, the dice and the text are all CSS. View source: there is no script tag. Pointless, slow, and it works.

Yes. It types a little under one character a second with nothing running but the style engine. With the temperature at zero it writes exactly what a plain Python run of the same weights writes. It's slow because every tick makes the browser redo 537 KB of stylesheet four times.

This one won't run in this browser. It depends on the CSS if() function, which only Chrome and Edge (137 or later) have so far, so in Safari and Firefox the text below just sits there. Nothing is broken on your end.

Watch it

Temperature Clock

The character it just picked

↵␣abcdefghijklmnopqrstuvwxyz.,;:!?'-&

Hidden layer: 192 neurons as 64 colours

Logits: 37 characters as 13 colours

The checkbox and the radio buttons work without script too: :has(#run:checked) pauses the clock animation, and the radios set the temperature. It stops adding text after 700 characters; reload to start again. If the text ever jumps back to the beginning, the browser skipped a beat: try the slow clock.

How one character gets made

Eight steps per character. None of them is JavaScript.

  1. CSS
    Tick.

    An animation steps a number through 0, 1, 2, 3, once round every 1200 ms. That's the clock. Everything else happens because that number changed.

  2. CSS
    Remember.

    A CSS property can't depend on itself, so "the last 8 characters" can't just be updated in place. Two 1 ms animations hold the state instead. Each is paused except during one clock phase: one copies the saved state to where the maths can read it, the other saves what the maths produced. This is the latch from Lyra Rebane's x86CSS.

  3. CSS
    Embed.

    if(style(--ct3: 12): …) picks the three colours for "character 12 at position 3". Eight positions make 24 colours.

  4. CSS
    Think.

    Two layers of colour maths, the same as the css page: each 3×3 block of weights is a relative colour, sums are color-mix() trees, ReLU is max(r, 0). Out come 13 colours holding 37 scores.

  5. CSS
    Roll the dice.

    A seed goes through sin(), mod() and log() to make 39 random numbers, which are added to the scores, scaled by the temperature. Picking the largest noisy score is the same as sampling from the model's odds (the Gumbel trick).

  6. CSS
    Find the largest.

    Still in colours: the larger of two colours, lane by lane, is their average plus half their absolute difference. A small tree of those gives the top score.

  7. CSS
    Turn a colour into a number.

    This was the hard part. CSS has no way to read a colour's channels as numbers. But subtracting the top score from every score leaves exactly one lane at zero, which can be turned into a pure red, green or blue, and style(--w4: color(srgb 0 1 0)) can ask whether a colour is exactly that. Thirteen questions give the character's number.

  8. CSS
    Write.

    The number picks a one-character string, which is appended to a property holding all the text so far. A ::after shows it with content. The context shifts along by one, and the next tick starts.

Pieces of the stylesheet

/* the clock: an animation that counts */
.clock { animation: tick 1200ms step-end infinite; }
@keyframes tick { 0% { --clock: 0 } 35% { --clock: 1 } 50% { --clock: 2 } 85% { --clock: 3 } }

/* the latch: two animations that only run on one clock phase each */
.cpu {
  animation: store 1ms infinite, execute 1ms infinite;
  animation-play-state: paused, paused;
  @container style(--clock: 1) { animation-play-state: running, paused }
  @container style(--clock: 3) { animation-play-state: paused, running }
}

/* a colour back into a number: the only bridge is asking "is it exactly this colour?" */
--k0: if(style(--w0: color(srgb 1 0 0)): 1; style(--w0: color(srgb 0 1 0)): 2; style(--w0: color(srgb 0 0 1)): 3; style(--w0: color(srgb 1 1 0)): 1; style(--w0: color(srgb 1 0 1)): 1; style(--w0: color(srgb 0 1 1)): 2; style(--w0: color(srgb 1 1 1)): 1; else: 0);

/* one character onto the end of the text */
--text: var(--__1text) var(--ch);

Real lines from this page. The whole machine is 537 KB of CSS and 177 registered properties, for 21,490 weights.

HTML the parts that aren't CSS

  • One checkbox and three radio buttons
  • Empty elements for the squares
  • The 37 characters in the "just picked" row
  • This explanation

CSS everything that happens

  • The clock and the memory
  • The embedding lookup and both layers
  • The random numbers and the sampling
  • Choosing the character and building the text
  • Pause, and the temperature

What it says

Gotchas found on the way