Demo
Rule 110 in HTML and CSS
A row of cells that rewrites itself by one simple rule, which mathematicians have proved can compute anything.
What it is
Rule 110 is a row of cells, each on or off, and one rule for working out the next row from the last.
Each cell looks at the three cells above it: above-left, directly above, and above-right. There are eight possible patterns, and Rule 110 says which of them switch the cell on:
| Above | 111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
|---|---|---|---|---|---|---|---|---|
| Cell | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
Read the bottom row as a binary number, 01101110, and you get 110: that's where the name comes from.
The top row is the starting pattern: click its cells to change it. Every row below follows from the row above, by Rule 110. CSS works out which cells should be on and marks them; your job is to click them, one row at a time. Get one wrong and CSS marks it with a cross.
Working example
Swipe the grid sideways to see the rest of it.
- On
- Should be on: click it
- Should be off: click it
How it works
Every cell is a checkbox, so HTML holds the whole grid: ticked is on, unticked is off. Each box is hidden, and the squares you see are its label. All the boxes come first in the page, in reading order, with all the labels after them, and that order matters.
The HTML
<input class="cell-box" type="checkbox" id="r0c0">
<input class="cell-box" type="checkbox" id="r0c1">
<!-- … every box, in reading order, then … -->
<label class="cell" for="r0c0">Row 1, cell 1</label>
<label class="cell" for="r0c1">Row 1, cell 2</label>
<!-- … every label, in the same order -->
Reaching the cells above
CSS's sibling combinator, ~, means "somewhere after this, in the same parent". It can only look forward,
so a label can be styled according to any box that comes before it, and here, every box does. Each rule is a chain:
it tests the boxes above a cell, then the cell's own box, and ends at the cell's label. The simplest has nothing to
test above it. It just draws a cell that's on.
Cell that's on source
#r1c4:checked ~ [for="r1c4"] {
--state: var(--cell-on);
}
When a cell should be on
Of the eight patterns, five switch a cell on. They could be written as five rules, but three conditions cover them all: the cell directly above is on and the one above-right is off; the cell above is off and the one above-right is on; or the cell above is on and the one above-left is off. If any of those holds and the cell's own box isn't ticked, the cell is drawn as one you need to click.
Should be on source
#r0c4:checked ~ #r0c5:not(:checked) ~ #r1c4:not(:checked) ~ [for="r1c4"] {
--state: var(--cell-missing);
--hint: ", should be on";
}
#r0c4:not(:checked) ~ #r0c5:checked ~ #r1c4:not(:checked) ~ [for="r1c4"] {
--state: var(--cell-missing);
--hint: ", should be on";
}
#r0c3:not(:checked) ~ #r0c4:checked ~ #r1c4:not(:checked) ~ [for="r1c4"] {
--state: var(--cell-missing);
--hint: ", should be on";
}
When a cell should be off
The other three patterns need two conditions: the cells above and above-right are both off; or all three are on. If either holds and the cell's own box is ticked, it's drawn as a mistake.
Should be off source
#r0c4:not(:checked) ~ #r0c5:not(:checked) ~ #r1c4:checked ~ [for="r1c4"] {
--state: var(--cell-wrong);
--hint: ", should be off";
}
#r0c3:checked ~ #r0c4:checked ~ #r0c5:checked ~ #r1c4:checked ~ [for="r1c4"] {
--state: var(--cell-wrong);
--hint: ", should be off";
}
Drawing the cells
None of those rules draws anything. Each sets a custom property, --state, and every cell paints itself
with whatever that is. A mistake's rule tests more boxes than the plain "on" rule does, which makes it more specific,
so it wins when both match.
A cell to click has a dot and a mistake has a cross, so nobody has to tell them apart by colour. The rules also set
--hint, words that CSS adds out of sight at the end of the cell's label. Text in a label is part of its
checkbox's name, so a screen reader says "Row 2, cell 16, should be on".
Drawing the cells source
.cell {
--state: var(--surface-alt);
--hint: '';
background: var(--state);
}
.cell::after {
content: var(--hint);
}
Written by a program
Every cell needs its own copy of those rules, naming its own boxes. Cells beyond the edges count as off, so the cells along the sides need fewer. For a grid 16 cells wide and 12 tall, that comes to 1039 selectors. Nobody wrote them by hand: a small program wrote them when the site was built, and tests check that its conditions match the rule table exactly. That's no different from a compiler turning code into machine instructions, but it's worth saying, because it's part of the honest answer.
The end result
Change the top row, and CSS works out the second. Click the cells it marks, and it works out the third, and so on down the grid. Each row is worked out from whatever is in the row above, right or wrong.
Why it matters
Rule 110 looks like a toy, but in 2004 Matthew Cook published a proof that, given a wide enough row and long enough, it can compute anything a computer can. It's Turing-complete. So anything that can run Rule 110 can, in principle, compute anything, and here HTML and CSS are running it, with one condition: you are the clock.
CSS knows what every row should be, but here it can't make it so. A rule can describe a state; it can't tick a box. So the machine only moves forward when you click, and it stops when the grid runs out. With the CSS every browser supports, that's as far as it goes: proof that HTML and CSS can compute anything, as long as someone turns the handle.
The newest CSS goes further. In 2026, x86CSS used a CSS animation as a clock, so that an emulated processor runs without anyone touching it, in the browsers that support the features it needs. Part 4 tells that story.