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
The character it just picked
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.
-
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.
-
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.
-
CSS
Embed.
if(style(--ct3: 12): …)picks the three colours for "character 12 at position 3". Eight positions make 24 colours. -
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 ismax(r, 0). Out come 13 colours holding 37 scores. -
CSS
Roll the dice.
A seed goes through
sin(),mod()andlog()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). -
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.
-
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. -
CSS
Write.
The number picks a one-character string, which is appended to a property holding all the text so far. A
::aftershows it withcontent. 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
- A stylesheet can run a loop. Nothing here is unrolled ahead of time. The same 537 KB of rules run again every tick, so it can write for as long as you leave the tab open.
- It's exact. At temperature 0 the first characters match a plain Python run of the same weights, character for character.
- The clock sets the speed, not the maths. Each of the four clock phases needs its own frame, and each frame makes the browser recompute the whole machine, which took about 100 ms in headless Chrome on a CPU. At 1200 ms a round it ran for 45 seconds without losing its place and wrote 0.8 characters a second. The fast setting only helps on a quicker machine.
- Colours are easy to write and nearly impossible to read. Any number can go into a colour. Getting one back out only works by asking whether a colour equals a specific colour, so the answer has to be made to land on a small set of exact colours first.
Gotchas found on the way
-
The state has to be saved in properties that are not registered with
@property. Registered ones don't latch. - A two-phase clock doesn't latch either. It needs rest phases in between, and if the browser is slow enough to skip a rest, the state resets to the start. That is why the rests are the longest part of each round, and why there is a slow setting.
-
CSS has no random function in this Chrome (it arrives in Chrome 156), so the randomness is a seed stepped by
mod()and scrambled withsin(). -
Chrome and Edge only. It needs
if(), which Safari and Firefox don't have yet, plus style queries, relative colours and unclamped colour channels. Reported not working in Safari on iOS.