Skip to content

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

QuestionWhat 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 testgrid.d of the UI-Q9 grid prototype (iterated further in experiments/ui-q9-iter/), integer-only: pixels on GUI, cells on a terminal
Engines probedChromium 156.0.8078.47, Firefox 150.0.1, WebKitGTK 2.54.1 (MiniBrowser)
Corpora readTaffy 497de49c (v0.16.0 prep), WPT 5b995ec7, csswg-drafts 9c7ee531
Builds onCSS Grid, Taffy, the grid prototype's notes, Codex's CSS fixtures
Prototypeexperiments/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 ​

ThingVersion, sourceNotes
Firefox (Gecko)150.0.1, a user profile--headless works
Chromium (Blink)156.0.8078.47, the dev shell's ($CHROME_BIN)--headless works
WebKitGTK2.54.1, the repository's nixpkgs (webkitgtk_4_1): MiniBrowser, WebKitWebDriverNo 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.0cog has been removed; no wpewebkit attribute
Taffy497de49c (v0.16.0 prep)MIT
WPT5b995ec7, cloned for this research (sparse, blobless, depth 1): css/css-grid, css/css-align, css/support, resources, fonts3-clause BSD
Speccsswg-drafts 9c7ee531, css-grid-2/Overview.bsW3C 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 (an x prefix 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.rs uses fantoccini to drive ChromeDriver against Chrome for Testing, latest Stable, unpinned (getchrome/src/lib.rs). It opens one page per fixture and calls getTestData() from test_helper.js, which reads inline style (specified values, not computed ones), the unrounded, naive and "smart" rounded rects, and the resolved grid-template-*. The result is written as language-neutral XML under tests/xml/<suite>/*.xml: an <input> tree with CSS-like attributes and an <expectations> tree of x 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. An H is 10×10, and &ZeroWidthSpace; 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 with grid-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.html has an unterminated style="…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.

dirtestscheckLayoutreftestsother testharnessuse Ahemwriting-mode / RTL
alignment45623016957264207
abspos21726153324857
grid-items24848195410638
subgrid1291810283142
layout-algorithm1064845134616
grid-definition94304222274
grid-model77195531113
placement4124170190
implicit-grids963050
top level702599109
parsing / animation750273——
  • checkLayout tests (resources/check-layout-th.js): 451 files carry about 9.3 k data-expected-width, 8.9 k -height, 6.9 k data-offset-x and 6.8 k -y assertions. They compare offsetWidth/offsetLeft (integer-snapped) with a tolerance of < 1 px.
    • 408 are static: no .style., classList, setAttribute or style-change.js mutation. 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 checkLayout tests, led by subgrid-baseline (18 files across kinds), line-names (15), standalone-axis-size (13), grid-gap (12) and repeat-auto-fill (9).
  • 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 WPT data-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 ​

EngineGrid / subgridUseful asLicence
Servo at 26c78689Grid is Taffy (taffy = "0.15.1"), so no subgridNot independent of Taffy; no extra signalMPL-2.0
Blitz at c3b584e2Stylo for CSS, stylo_taffy for Taffy layoutA CSS → Taffy-style bridge to copy from; same algorithm as TaffyMIT/Apache
Ladybird at 4c574ef9Its 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 pathsA possible fourth vote. Its dumps use a real font and engine-specific trees, so they are poor goldens. nixpkgs ladybird is from 2026-04BSD-2
Yoga at 3a201ff4Grid style types only (GridStyle.h, GridTrack.h, GridLine.h), no algorithm in yoga/algorithm/. Its gentest has no grid fixturesNothing yetMIT
Taffy (as a live engine)Grid Level 1, no subgridA 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 ChromeMIT

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:

    1. Puts all 592 Taffy grid fixtures into one page, each fixture isolated in its own srcdoc iframe with the base CSS and test_helper.js (16 in flight at a time).
    2. Calls describeElement on each fixture and POSTs one JSON document to a localhost server.
    3. 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.
  • Speed for 592 fixtures, about 3 k boxes:

    Enginein-pagewall incl. start-up
    Chromium 1562.8 s (≈ 5 ms per fixture)3.3 s
    Firefox 1503.9 s4.1–5.0 s
    WebKitGTK 2.5417.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] and grid_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:

    1. WebKitGTK under Xvfb's default DPI scales everything: a width: 10px box measured 9.9965 and Ahem "HHHH" 42.27. Pass xvfb-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.
    2. Scrollbar width differs by engine (Chromium 15 px with Taffy's ::-webkit-scrollbar, Firefox 12). Fixtures must not depend on scrollbars.
    3. Malformed fixture HTML spills into its neighbours unless each fixture is isolated.
    4. When a test-only JS payload is embedded inside <script>, escape </.

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 ​

OptionFidelityGridSubgridIntrinsic + textSpeedDeterminismOffline / NixLicence
3-engine batch harness (plain process + POST)Real browsers; majority voteFullFull (Gecko, Blink and WebKit all ship it)Exact with Ahem or atomic boxes3–20 s per 600 fixturesIdentical across runs, given fixed version and DPIAll three engines in the store / nixpkgsEngines MPL / BSD / LGPL, used as tools only
Same, through WebDriver BiDi / CDP / MarionetteSameSameSameSameSlightly slower; better crash and timeout controlSamegeckodriver 0.36, chromedriver 147, WebKitWebDriver in nixpkgsSame
PlaywrightSame, but its WebKit is a Playwright forkSameSameSameSameSameplaywright-driver 1.56.1; its browsers are big fetchesApache-2.0
Taffy XML goldens, importedChrome only (an unpinned version)Good Level 1 coverageNoneAhem textFree (static files)StaticA flake inputMIT
WPT checkLayoutSpec-author numbers (< 1px)Broad18 testsAhemFree once convertedStaticClonedBSD-3
WPT reftestsPass/fail onlyBroad102 tests—Needs a browser—ClonedBSD-3
Taffy live (FFI / subprocess)≈ ChromeLevel 1NoneMeasure functionsµs per caseDeterministicCargo buildMIT
LadybirdA fourth vote; immature in placesYesYesReal fontsHeavy?nixpkgs 2026-04; a big closureBSD-2
Servo / Blitz= TaffyLevel 1None————MPL / MIT
Yoga—No algorithm—————MIT
Spec, worked by handGround truthAnyAnyAnySlow (by a human)——W3C

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, subgrid per axis and nested children;
    • each item: placement, size/min/max, margins, padding, border, align/justify self, and either children or a text atom list.
  • Text as atoms. Write text as Ahem H runs separated by &ZeroWidthSpace;, with font: 10px/1 Ahem (as Taffy does). Alternatively, use display: inline-block boxes 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 h of every node relative to its parent, the resolved track lists, the engine versions, and a vote record.

5.2 Sources ​

  1. 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.
  2. WPT static checkLayout tests. Harvest the computed style and boxes of the ~150–200 horizontal, in-flow tests, and keep data-expected-* as a second check.
  3. 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.
  4. 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 a ci css-oracle regen subcommand.
    • 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 MiniBrowser under xvfb-run -dpi 96, as flake packages; the opt-in ui-research shell already carries them, and they stay out of ciPackages. It collects the POSTed 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.
  • 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 reviewed disputed.json with 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 for center/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 (with wired, 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. disputed fixtures 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 test with plenty of headroom.

5.7 Fuzzing loop ​

  • Nightly or @slow, never inside ci test:
    1. The D generator emits N seeds.
    2. Run Taffy in-process (fast; non-subgrid only) and our engine on each.
    3. Send only the interesting cases to the three browsers in a batch: disagreements, or a random 1 % sample.
    4. Vote.
    5. If our engine disagrees with an agreed or majority result, 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.
    6. 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 ​

StepWorkDays
1Fixture JSON schema, plus fixture → HTML renderer (D)2
2Batch harness in D: localhost server, 3 engine launchers, calibration probe, iframe batching, version stamping; flake packages3–4
3Golden writer, vote policy, disputed.json, drift report2
4D unittest consumer (shards, unit 1 and unit 10, diff printer)1–2
5Taffy import (filter to our model, translate the XML or re-harvest)1–2
6WPT static checkLayout harvest and filter3–4
7Subgrid seed set (WPT, Ladybird, hand-written from spec §9)3–5
8Random generator, Taffy-in-process differential, shrinker, nightly job5–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 ​