TL;DR
Multimodal LLMs can turn a UI screenshot into HTML/CSS in seconds, yet they often botch the underlying page architecture—stacking pricing cards vertically when they belong in a row, or dropping buttons altogether. Instead of regenerating whole pages from scratch, this paper introduces Render Structure Uncertainty (RSU), a plug-and-play post-generation repair layer. By treating HTML debugging as an uncertainty-guided search over actual browser render traces rather than raw code or pixels, RSU surgically diagnoses and fixes broken layout subtrees without retraining the base model.
What Problem Does This Paper Address?
Asking an MLLM to write front-end code from a design image (UI-to-Code) works remarkably well until you inspect the structural fidelity. Existing pipelines commit to a layout plan upfront; when they misplace a wrapper boundary or choose the wrong flex direction, they lack a reliable mechanism to go back and fix it.
Why is automated post-hoc HTML repair so tricky? Anyone who has ever wrestled with CSS late at night knows the answer: ambiguity. The authors formalize two distinct flavours of it:
- Attribution Uncertainty: If three pricing cards render as a vertical column instead of a horizontal row, which node in the Document Object Model (DOM—the browser's tree representation of HTML) is the culprit? Is it the outer
<section>, an intermediate<div class="cards">wrapper, or styling on the individual<article>items? Looking at pixels alone doesn't uniquely pinpoint the bug. - Repair Uncertainty: Even once you pick a DOM subtree to rewrite, multiple valid code implementations (CSS Grid, Flexbox row, semantic list) produce different rendered behaviours in the context of the full page.
Committing prematurely to a single error location or a single code edit often makes the page worse.
Methods
RSU attaches to any existing HTML generator at test time and lifts comparison out of pixel space into a shared render-structure space. It works in four stages:
- Structure Graph Construction: A trained parser converts the target screenshot into a visual structure graph (capturing regions, buttons, repeat groups, and spatial relations like same row or inside). Simultaneously, RSU executes the generated HTML in a headless Chromium browser, extracting bounding boxes and computed styles to build a DOM-anchored render structure graph—linking every visual region directly back to the code subtree that produced it.
- Modeling Attribution Uncertainty: RSU hierarchically matches the two graphs to spot missing slots, extra elements, and relation mismatches. Instead of guessing one broken node, it maps mismatches to plausible replaceable subtrees ("DOM holes"—including lowest common layout ancestors and nearby wrappers) and uses greedy set cover to pick a compact set of $B=3$ holes. (If the holes cover less than $60\%$ of mismatches, it triggers a full-page fallback.)
- Modeling Repair Uncertainty: For each hole, the MLLM generates $K=8$ targeted local rewrites conditioned on the specific mismatch type, always keeping one "no-op" candidate (the untouched original subtree). Crucially, RSU renders each edit in the full page and clusters them not by how their text code looks, but by a render-structure signature (bounding boxes, layout relations, slot counts, roles, and invalid states like overflow or overlap).
- Global Reranking: Retaining the top $L_c=3$ behavioural cluster representatives per hole, RSU composes combinations across all holes and picks the winner using an equal-weighted structural score (visual similarity, layout F1, slot F1, and role F1), zeroing out pages with severe overlap or disappearing content.
Datasets
No new benchmarks are introduced; the authors rely on established protocols with strict data isolation:
- Design2Code: 484 real-world webpage screenshot–HTML pairs spanning diverse domains, serving as the standard evaluation benchmark.
- ScreenBench: 1,000 contemporary websites heavy on complex nested CSS Grid and Flexbox layouts, used as a tougher out-of-distribution testbed.
- Web-crawl corpus: A separate, non-overlapping split of rendered webpages used to generate compressed DOM pseudo-labels for training the screenshot structure parser.
Key Insights and Ideas
- Cluster by browser behaviour, not source code: Two snippets of HTML/CSS can look completely different in text edit-distance yet render identically—or differ by a single CSS property (
flex-direction) and completely rearrange the screen. Clustering repairs by rendered signatures ensures true diversity among candidates. - Joint composition beats greedy local fixes: Fixing Hole A with its locally highest-scoring snippet and Hole B with its locally best snippet can cause cross-component layout collisions. Reranking composed combinations globally resolves these dependencies.
- The power of doing nothing: Including the original "no-op" subtree in every hole's candidate pool guarantees that RSU never degrades the page relative to its internal structural score.
- Smart localization beats brute-force sampling: Spending 52 browser renders on targeted, graph-matched DOM holes handily beats generating 52 full pages from scratch (best-of-$K$) or picking holes via pixel-difference heuristics.
Key Results
Evaluated across four MLLM backbones (GPT-4o, Claude-3.5-Sonnet, Gemini-2.5-Pro, and Qwen2.5-VL), RSU consistently outperforms single-pass prompting (Direct) and structured multi-agent/hierarchical pipelines (DCGen, UICopilot, ScreenCoder):
- Structural Layout Gains: On Design2Code with GPT-4o, RSU boosts the layout-sensitive Position score from
0.893(Direct) and0.916(ScreenCoder) up to0.942, and Block recall from0.838to0.876. - Out-of-Distribution Robustness: On the harder ScreenBench dataset (GPT-4o), RSU lifts Position from
0.715(Direct) and0.746(ScreenCoder) to0.774, with similar margins across open-source Qwen2.5-VL (0.603$\rightarrow$0.655Position). - Budget-Matched Dominance: Capped at an identical budget of 52 browser renders on GPT-4o, RSU (
0.942Position) substantially outperforms full-page best-of-$K$ (0.906), full-page self-repair (0.903), and pixel-residual hole repair (0.913). Because candidate renders are independent, wall-clock latency scales to that of a single render given parallel browser workers.
Limitations and Future Work
- Internal Score vs. Human Judgment: The theoretical non-degradation guarantee holds strictly with respect to RSU's internal heuristic scoring function $Q$; the authors candidly note this does not guarantee calibrated risk or universal preference under human evaluation.
- Initial DOM Viability: Local subtree surgery assumes the base page isn't catastrophically broken. When selected holes explain fewer than $60\%$ of structural mismatches ($\kappa < 0.6$), RSU abandons local repair for a global full-page fallback.
(Directions for future work are not explicitly discussed in the paper.)
Summary updated