A CSS Grid oracle: browsers as the source of expected layouts
Which engines, corpora and harness should give the expected layouts for an integer CSS Grid Level 2 and subgrid engine, measured on the three browser engines and on Taffy's and WPT's grid suites.
Last reviewed: November 28, 2026
| Question | What should give expected layouts for the UI-Q9 grid engine, at thousands of fixtures plus random differential testing, inside a warm ci test of about 1 s? |
| Engine under test | grid.d of the UI-Q9 grid prototype (iterated further in experiments/ui-q9-iter/), integer-only: pixels on GUI, cells on a terminal |
| Engines probed | Chromium 156.0.8078.47, Firefox 150.0.1, WebKitGTK 2.54.1 (MiniBrowser) |
| Corpora read | Taffy 497de49c (v0.16.0 prep), WPT 5b995ec7, csswg-drafts 9c7ee531 |
| Builds on | CSS Grid, Taffy, the grid prototype's notes, Codex's CSS fixtures |
| Prototype | experiments/css-grid-oracle/: throwaway Python, kept as evidence, to be rewritten in D |
The engine takes track functions (px, %, fr, minmax, fit-content, auto, min-/max-content), repeat(auto-fill / auto-fit), line, span, negative-line and area placement, sparse and dense flow, gaps, justify/align-items/-self/-content, first-baseline alignment, subgrid in one or both axes, and intrinsic min/max-content text.
The answer in one line: treat real browsers as the oracle, offline, through a Nix-pinned three-engine batch harness. It writes integer-friendly JSON goldens into the repository. The D tests only read those goldens, so they take milliseconds. Start the corpus from Taffy's 592 grid fixtures and from WPT's ~408 static checkLayout tests. Fill the gap that both leave (subgrid, and text as fixed-width atoms) with our own generator and fuzzer.
1. What the research machine had
| Thing | Version, source | Notes |
|---|---|---|
| Firefox (Gecko) | 150.0.1, a user profile | --headless works |
| Chromium (Blink) | 156.0.8078.47, the dev shell's ($CHROME_BIN) | --headless works |
| WebKitGTK | 2.54.1, the repository's nixpkgs (webkitgtk_4_1): MiniBrowser, WebKitWebDriver | No headless flag; runs under xvfb-run |
| nixpkgs (registry) | rev 0c88e1f2: firefox 150.0.1, chromium 147.0.7727.137, geckodriver 0.36.0, chromedriver 147.0.7727.137, playwright-driver 1.56.1, ladybird 0-unstable-2026-04-04, servo 0.1.0 | cog has been removed; no wpewebkit attribute |
| Taffy | 497de49c (v0.16.0 prep) | MIT |
| WPT | 5b995ec7, cloned for this research (sparse, blobless, depth 1): css/css-grid, css/css-align, css/support, resources, fonts | 3-clause BSD |
| Spec | csswg-drafts 9c7ee531, css-grid-2/Overview.bs | W3C document licence |
The prototype ran on a Python 3.13 from the store, with -I. The production harness should be D (see §6).
2. The corpora
2.1 Taffy test_fixtures/ and gentest
- Counts at
497de49:grid/holds 595 HTML fixtures, 592 of them active (anxprefix disables one). Other directories:blockgrid/14,gridflex/11, and 1,086 more for flex, block and others. Each fixture becomes four tests (border/content box × LTR/RTL), so there are 2,368 generated grid XML goldens (6,696 in all) (fixtures). - How they are made:
scripts/gentest/src/main.rsusesfantoccinito drive ChromeDriver against Chrome for Testing, latest Stable, unpinned (getchrome/src/lib.rs). It opens one page per fixture and callsgetTestData()fromtest_helper.js, which reads inlinestyle(specified values, not computed ones), the unrounded, naive and "smart" rounded rects, and the resolvedgrid-template-*. The result is written as language-neutral XML undertests/xml/<suite>/*.xml: an<input>tree with CSS-like attributes and an<expectations>tree ofx y width height resolved-rows resolved-columns. This is effectively a golden format already, and it could be imported directly. - Text: text uses Ahem at 10 px with
line-height: 1. AnHis 10×10, and​marks break opportunities (test_base_style.css). Min- and max-content are therefore exact integers. 136 of the 592 grid fixtures contain text. - Rounding: the "smart" rounding is
round(right) - round(left), i.e. rounding the edges. Only 3 of the 592 border-box LTR goldens contain a fractional value. - Coverage: prefixes include
grid_flex_track_intrinsic_sizes_*(137), absolute (50), align/justify (78), minmax (32), intrinsic (31), overlarge (30), span (26), fr (24), percent (18), fit-content (14), aspect ratio (14) and 27 baseline fixtures. There is only one fixture withgrid-template-areas. - Subgrid: none. Taffy does not implement subgrid. Its CHANGELOG lists subgrid as unsupported, and issue
#468"Support CSS Grid Level 2 (Subgrid)" is still open. Masonry is#910. - Upstream bug found:
grid_span_2_max_content_auto_indefinite_hidden.htmlhas an unterminatedstyle="…overflow: hidden;>attribute. That fixture really tests a parse-error recovery. When the fixtures were concatenated into one page, it swallowed the next 20 fixtures. See §3.
2.2 WPT css/css-grid/ at 5b995ec
These counts exclude -ref files, support/ and crash tests. grid-lanes/ (1,064 masonry tests) is out of scope.
| dir | tests | checkLayout | reftests | other testharness | use Ahem | writing-mode / RTL |
|---|---|---|---|---|---|---|
| alignment | 456 | 230 | 169 | 57 | 264 | 207 |
| abspos | 217 | 26 | 153 | 32 | 48 | 57 |
| grid-items | 248 | 48 | 195 | 4 | 106 | 38 |
| subgrid | 129 | 18 | 102 | 8 | 31 | 42 |
| layout-algorithm | 106 | 48 | 45 | 13 | 46 | 16 |
| grid-definition | 94 | 30 | 42 | 22 | 27 | 4 |
| grid-model | 77 | 19 | 55 | 3 | 11 | 13 |
| placement | 41 | 24 | 17 | 0 | 19 | 0 |
| implicit-grids | 9 | 6 | 3 | 0 | 5 | 0 |
| top level | 70 | 2 | 59 | 9 | 10 | 9 |
| parsing / animation | 75 | 0 | 2 | 73 | — | — |
checkLayouttests (resources/check-layout-th.js): 451 files carry about 9.3 kdata-expected-width, 8.9 k-height, 6.9 kdata-offset-xand 6.8 k-yassertions. They compareoffsetWidth/offsetLeft(integer-snapped) with a tolerance of < 1 px.- 408 are static: no
.style.,classList,setAttributeorstyle-change.jsmutation. Of those, 252 use Ahem, 198 use vertical writing modes, 101 use absolute positioning and 17 are subgrid tests. - So roughly 150–200 are horizontal, in-flow and convertible to our input model.
- Subgrid has only 18
checkLayouttests, led bysubgrid-baseline(18 files across kinds),line-names(15),standalone-axis-size(13),grid-gap(12) andrepeat-auto-fill(9).
- 408 are static: no
- Can they be converted by machine?
checkLayout: yes, partly. A converter loads each test in a browser, serialises the computed grid properties of every grid container and item together with its box, and keeps the WPTdata-expected-*values as a second, spec-authored check. The hard part is not the geometry but expressing arbitrary CSS (shared classes,font: 10px/1 Ahem, writing modes, margins, borders) in our input model. Drop any test that uses something our model lacks: vertical writing modes, abspos, replaced elements, scrollbars.- Reftests (~1.8 k): these have no numbers. They become goldens only by harvesting what the browsers lay out for the test page. That is trustworthy where wpt.fyi says the engine passes the test (the reftest then certifies the browser's rendering, and the geometry follows).
- Spec as a tie-breaker:
css-grid-2/Overview.bs, with §9 Subgrids, line 3555, §11 Grid Layout Algorithm, line 4355, §11.5 Resolve intrinsic track sizes, line 4703 and §11.7 Expand flexible tracks, line 5211.
2.3 Other engines, as engines or as corpora
| Engine | Grid / subgrid | Useful as | Licence |
|---|---|---|---|
Servo at 26c78689 | Grid is Taffy (taffy = "0.15.1"), so no subgrid | Not independent of Taffy; no extra signal | MPL-2.0 |
Blitz at c3b584e2 | Stylo for CSS, stylo_taffy for Taffy layout | A CSS → Taffy-style bridge to copy from; same algorithm as Taffy | MIT/Apache |
Ladybird at 4c574ef9 | Its own GFC, now in Rust: 7,764 lines, 374 mentions of subgrid. 245 Tests/LibWeb/Layout/input/grid/ tests (28 subgrid) with text dump expectations, plus about 1,843 imported WPT css-grid paths | A possible fourth vote. Its dumps use a real font and engine-specific trees, so they are poor goldens. nixpkgs ladybird is from 2026-04 | BSD-2 |
Yoga at 3a201ff4 | Grid style types only (GridStyle.h, GridTrack.h, GridLine.h), no algorithm in yoga/algorithm/. Its gentest has no grid fixtures | Nothing yet | MIT |
| Taffy (as a live engine) | Grid Level 1, no subgrid | A cheap, deterministic in-process second opinion for non-subgrid fuzzing (a cdylib via the C ABI, or a small Rust subprocess reading our JSON). Never ground truth: it is calibrated to Chrome | MIT |
3. Prototype: three engines, one batch, timed
The scripts are in experiments/css-grid-oracle/, with every engine's output and the comparison; its README says how to re-run them from the repository.
What it does:
- Puts all 592 Taffy grid fixtures into one page, each fixture isolated in its own
srcdociframe with the base CSS andtest_helper.js(16 in flight at a time). - Calls
describeElementon each fixture andPOSTs one JSON document to a localhost server. - Uses no WebDriver: the browser is just
firefox --headless/chromium --headless/xvfb-run MiniBrowser. This extends Codex's probe, which does the same for 10 hand-written cases in Firefox only.
- Puts all 592 Taffy grid fixtures into one page, each fixture isolated in its own
Speed for 592 fixtures, about 3 k boxes:
Engine in-page wall incl. start-up Chromium 156 2.8 s (≈ 5 ms per fixture) 3.3 s Firefox 150 3.9 s 4.1–5.0 s WebKitGTK 2.54 17.7 s ≈ 19–24 s (Xvfb start-up is part of that) - Without iframes, everything in one document, Chromium needs only 0.09 s. Firefox, though, is quadratic there: 36 s at first, and more than 400 s once every fixture measured correctly (it never finished). Isolation is therefore required both for correctness and for speed.
- A generator run over 10 k fixtures with all three engines in parallel is a few minutes. That is fine for regeneration, and it is why the browsers stay out of
ci test.
Determinism: two runs each of Chromium and Firefox gave identical results; only the timing field differs.
Fidelity checks:
- Chromium 156 reproduced Taffy's Chrome-generated XML goldens for 591 of 592 fixtures. The one difference is a root-margin artefact of the comparison.
- Three-engine agreement, exact on every rounded box (
compare.txt):- all three: 538/592 (91 %)
- 2-of-3 majority: 51, with Firefox the odd one out 35 times, WebKit 16 times and Chromium never. Taffy wrote these fixtures against Chrome, which explains the zero.
- no majority: 3 (
grid_span_13_most_non_flex_with_minmax_indefinite[_hidden]andgrid_absolute_safe_static_outer_cb_tentative)
- Most disagreements are in spanning intrinsic sizing (
grid_span_*12,grid_minimum_*6), abspos 5, scrollbars/overflow 5 and fr 4. These are real divergences, not rounding noise: of the 51 odd-one-out cases, 38 differ by more than 5 px (Firefox 24 of 35, WebKit 14 of 16), and only 1 differs by at most 1 px.
Hazards found along the way:
- WebKitGTK under Xvfb's default DPI scales everything: a
width: 10pxbox measured 9.9965 and Ahem "HHHH" 42.27. Passxvfb-run -s "-screen 0 1280x1024x24 -dpi 96". That made it exactly 10 and 40 and raised WebKit's agreement with Chromium from 458 to 573. Every harness run should start with a calibration probe: assert that a 10 px box is 10 and that Ahem "HHHH" is 40. - Scrollbar width differs by engine (Chromium 15 px with Taffy's
::-webkit-scrollbar, Firefox 12). Fixtures must not depend on scrollbars. - Malformed fixture HTML spills into its neighbours unless each fixture is isolated.
- When a test-only JS payload is embedded inside
<script>, escape</.
- WebKitGTK under Xvfb's default DPI scales everything: a
NOTE
Re-run from the repository on November 28, 2026, the comparison is unchanged. Chromium and WebKitGTK are the repository's nixpkgs builds at the run's versions; Firefox there is 158.0.1, which lays out every box as 150.0.1 did.
4. The options compared
| Option | Fidelity | Grid | Subgrid | Intrinsic + text | Speed | Determinism | Offline / Nix | Licence |
|---|---|---|---|---|---|---|---|---|
3-engine batch harness (plain process + POST) | Real browsers; majority vote | Full | Full (Gecko, Blink and WebKit all ship it) | Exact with Ahem or atomic boxes | 3–20 s per 600 fixtures | Identical across runs, given fixed version and DPI | All three engines in the store / nixpkgs | Engines MPL / BSD / LGPL, used as tools only |
| Same, through WebDriver BiDi / CDP / Marionette | Same | Same | Same | Same | Slightly slower; better crash and timeout control | Same | geckodriver 0.36, chromedriver 147, WebKitWebDriver in nixpkgs | Same |
| Playwright | Same, but its WebKit is a Playwright fork | Same | Same | Same | Same | Same | playwright-driver 1.56.1; its browsers are big fetches | Apache-2.0 |
| Taffy XML goldens, imported | Chrome only (an unpinned version) | Good Level 1 coverage | None | Ahem text | Free (static files) | Static | A flake input | MIT |
WPT checkLayout | Spec-author numbers (< 1px) | Broad | 18 tests | Ahem | Free once converted | Static | Cloned | BSD-3 |
| WPT reftests | Pass/fail only | Broad | 102 tests | — | Needs a browser | — | Cloned | BSD-3 |
| Taffy live (FFI / subprocess) | ≈ Chrome | Level 1 | None | Measure functions | µs per case | Deterministic | Cargo build | MIT |
| Ladybird | A fourth vote; immature in places | Yes | Yes | Real fonts | Heavy | ? | nixpkgs 2026-04; a big closure | BSD-2 |
| Servo / Blitz | = Taffy | Level 1 | None | — | — | — | — | MPL / MIT |
| Yoga | — | No algorithm | — | — | — | — | — | MIT |
| Spec, worked by hand | Ground truth | Any | Any | Any | Slow (by a human) | — | — | W3C |
5. Recommended pipeline
5.1 Fixture model: integer-friendly by construction
- One language-neutral JSON schema, a subset of our engine's input:
- the container: width/height (definite px or
min-content/max-content/ an available space), tracks,repeat, gaps, areas, flow, the alignment properties,subgridper axis and nested children; - each item: placement, size/min/max, margins, padding, border, align/justify self, and either children or a text atom list.
- the container: width/height (definite px or
- Text as atoms. Write text as Ahem
Hruns separated by​, withfont: 10px/1 Ahem(as Taffy does). Alternatively, usedisplay: inline-blockboxes of fixed width and height separated by break opportunities, which needs no font. Either makes min-content (the widest atom) and max-content (the sum of atoms) exact integers. With 1 unit = 10 px (Ahem) or 1 cell, the same golden serves GUI and terminal: divide by the unit, and require that every expected value is a multiple of the unit. - Expectations: border-box
x y w hof every node relative to its parent, the resolved track lists, the engine versions, and a vote record.
5.2 Sources
- Taffy grid fixtures (592 × 4 variants). Import them through our harness, or translate the XML directly. Drop any fixture that uses features outside our model: abspos, aspect ratio, scrollbars, overflow, the overlarge-limit tests. Expect about 350–450 to remain.
- WPT static
checkLayouttests. Harvest the computed style and boxes of the ~150–200 horizontal, in-flow tests, and keepdata-expected-*as a second check. - WPT subgrid reftests and tests (129) and the Ladybird subgrid inputs (28). Translate them by hand or semi-automatically into our schema. This is the seed set for subgrid.
- Our generator. Seeded random fixtures over the grammar in 5.1, weighted towards the spec's hard parts: spanning items across intrinsic and flexible tracks (§11.5), fr below 1 summing to less than 1 (§11.7),
fit-content, auto-fit collapse, dense packing, baseline groups, and subgrid gaps, line names, margin/padding/border "phantom" contributions and nesting depth. Target 2–5 k checked-in fixtures, then grow.
5.3 Generator / oracle runner (slow, not in ci test)
- A D tool:
apps/css-oracle, or aci css-oracle regensubcommand.- It renders each JSON fixture to HTML and serves a batch page per engine over localhost (
sparkles:http). - It launches the Nix-pinned browsers: firefox, chromium, and webkitgtk
MiniBrowserunderxvfb-run -dpi 96, as flake packages; the opt-inui-researchshell already carries them, and they stay out ofciPackages. It collects thePOSTed JSON and writes goldens. - It runs the calibration probe first (a 10 px box, Ahem "HHHH" = 40).
- It uses per-fixture iframes, K in flight, and one process per engine in parallel.
- Later, move to WebDriver BiDi only if crash or timeout handling demands it.
- It renders each JSON fixture to HTML and serves a batch page per engine over localhost (
- Pin versions. Record the engine versions in every golden file, and regenerate only when the flake lock moves. Taffy's unpinned Chrome for Testing is the anti-pattern to avoid.
5.4 Multi-engine agreement policy
- Unanimous, all 3 exact →
status: "agreed", a hard golden. This was 91 % of the Taffy corpus. - 2-of-3 majority →
status: "majority". Use the majority value, and name the dissenting engine. A short-lived dissent is usually a bug in that engine, and the fixture links the bug when there is one. These fixtures still gate CI. - No majority, or the result contradicts the spec on inspection →
status: "disputed". These fixtures do not gate. They sit in a revieweddisputed.jsonwith the spec section and the answer we chose by hand from the spec (spec-override), which then gates. - The spec beats a majority only through an explicit, reviewed override. The Salas "infinitely growable" example in the UI-Q9 iteration's notes (
experiments/ui-q9-iter/NOTES.md) is exactly that kind of case. - Track engine drift. On regeneration, report fixtures whose status or values changed. An engine fix that turns a majority into a unanimous result is good news; a unanimous result breaking is a red flag.
5.5 Mapping fractional px onto integers
- Prefer integer-exact fixtures. Keep a fixture in the exact tier only if every engine's unrounded rects are integers; record this as
exact: true. Choose generator parameters to keep it so: container sizes divisible by the fr sum, even free space forcenter/space-*. - Otherwise store the unrounded values, take the median over the engines, and compare tolerance-wise. Gecko uses 1/60 px app units, while Blink and WebKit use 1/64 px LayoutUnit, so exact fractions differ between engines anyway.
- Each edge of ours must be within 1 unit of the oracle edge.
- Sizes must stay consistent: sibling edges abut, and track sums plus gaps equal the content box.
- Cross-check our distribution rule (where the remainder goes) against the edge-rounded values, as Taffy's smart rounding does.
- Never compare rounded widths. Compare rounded edges: per-box rounding of widths accumulates errors that look like 1 px gaps.
5.6 How the D tests consume it
- The goldens live in
libs/<grid-lib>/test/oracle/*.json, sharded at about 500 fixtures per file. - A
@("grid.oracle.<shard>")unittest per shard parses the shard (withwired, or a tiny reader), builds the grid tree, lays it out at unit 1 (cells) and at unit 10 (px), and diffs every box. - On failure it prints the fixture id, the vote status and a minimal diff.
disputedfixtures are skipped with a count. - Budget: the prototype engine costs about 3–8 k layout queries per page, so 5 k small fixtures take tens of milliseconds, and JSON parsing a similar amount. That fits the 1 s warm
ci testwith plenty of headroom.
5.7 Fuzzing loop
- Nightly or
@slow, never insideci test:- The D generator emits N seeds.
- Run Taffy in-process (fast; non-subgrid only) and our engine on each.
- Send only the interesting cases to the three browsers in a batch: disagreements, or a random 1 % sample.
- Vote.
- If our engine disagrees with an
agreedormajorityresult, shrink the case with delta debugging over the fixture tree (drop items and tracks, simplify track functions, halve sizes), re-voting the browsers at each step. The oracle is about 5 ms per fixture in Chromium, and the final shrunk case is confirmed on all three engines. - Write the shrunk case into the corpus as a new golden.
- Coverage-guided weighting is optional: count which spec steps fired, using
code-instrumentation, and bias the generator towards rare steps.
6. Work estimate
| Step | Work | Days |
|---|---|---|
| 1 | Fixture JSON schema, plus fixture → HTML renderer (D) | 2 |
| 2 | Batch harness in D: localhost server, 3 engine launchers, calibration probe, iframe batching, version stamping; flake packages | 3–4 |
| 3 | Golden writer, vote policy, disputed.json, drift report | 2 |
| 4 | D unittest consumer (shards, unit 1 and unit 10, diff printer) | 1–2 |
| 5 | Taffy import (filter to our model, translate the XML or re-harvest) | 1–2 |
| 6 | WPT static checkLayout harvest and filter | 3–4 |
| 7 | Subgrid seed set (WPT, Ladybird, hand-written from spec §9) | 3–5 |
| 8 | Random generator, Taffy-in-process differential, shrinker, nightly job | 5–7 |
| Total | ≈ 20–28 days (4–6 weeks); steps 1–5 alone (≈ 2 weeks) give 400+ gating fixtures |
7. Open points
- Margins, padding, borders and box-sizing are not clearly in
grid.d's input model. The generator should tag each fixture with the features it uses, so the D side can skip what it does not support yet. - Baseline alignment depends on font metrics: use Ahem, whose ascent is 0.8 em. Treat baseline fixtures as Ahem-only.
- wpt.fyi results (online) could pre-filter WPT reftests to the ones every engine passes. That has not been done here.
Sources
- Taffy at
497de49c:test_fixtures/grid,gentest/src/main.rs,getchrome/src/lib.rs,test_helper.js,test_base_style.css,CHANGELOG.md; issue#468 - WPT at
5b995ec7:check-layout-th.js - CSS Grid Level 2 at
9c7ee531: §9, §11, §11.5, §11.7 - Servo
26c78689, Blitzc3b584e2, Ladybird4c574ef9, Yoga3a201ff4 - Prototype and runs:
experiments/css-grid-oracle/