Source-linked AI summary

ScreenCoder: Advancing Visual-to-Code Generation for Front-End Automation via Modular Multimodal Agents

Yilei Jiang, Yaozhi Zheng, Yuxuan Wan, Jiaming Han, Qunzhong Wang, Michael R. Lyu, Xiangyu Yue

arXiv:2507.22827v2cs.CV

TL;DR

UI-to-code generation remains difficult because MLLMs must unify visual perception, layout planning, and code synthesis, producing recurring perception and planning errors on complex interfaces. ScreenCoder addresses this with modular grounding, planning, and generation agents, while also generating training data and supporting post-training. The paper reports state-of-the-art performance in visual fidelity, structural coherence, and code correctness.

  • Problem

    MLLMs struggle with complex UI-to-code generation because a monolithic model must jointly perform visual perception, layout planning, and code synthesis.

    Source: §1 · p. 2, §3 · p. 3
  • Method

    ScreenCoder decomposes UI-to-code generation into grounding, planning, and generation, and uses the framework as a scalable data engine for supervised fine-tuning and reinforcement learning.

    Source: §1 · p. 2
  • Results

    ScreenCoder achieves state-of-the-art performance in layout fidelity, structural coherence, generation quality, visual fidelity, and code correctness.

    Source: §1 · p. 2, §8 · p. 9
  • Takeaways & Limitations

    The framework provides a practical solution for front-end automation and a foundation for future research in multimodal program synthesis.

    Source: §8 · p. 9

    High-quality generation takes tens of seconds, creating a computational cost-quality trade-off for the workflow.

    Source: §7 · p. 9

Abstract

from arXiv · show

Automating the transformation of user interface (UI) designs into front-end code holds significant promise for accelerating software development and democratizing design workflows. While multimodal large language models (MLLMs) can translate images to code, they often fail on complex UIs, struggling to unify visual perception, layout planning, and code synthesis within a single monolithic model, which leads to frequent perception and planning errors. To address this, we propose ScreenCoder, a modular multi-agent framework that decomposes the task into three interpretable stages: grounding, planning, and generation. By assigning these distinct responsibilities to specialized agents, our framework achieves significantly higher robustness and fidelity than end-to-end approaches. Furthermore, ScreenCoder serves as a scalable data engine, enabling us to generate high-quality image-code pairs. We use this data to fine-tune open-source MLLM via a dual-stage pipeline of supervised fine-tuning and reinforcement learning, demonstrating substantial gains in its UI generation capabilities. Extensive experiments demonstrate that our approach achieves state-of-the-art performance in layout accuracy, structural coherence, and code correctness. Our code is made publicly available at https://github.com/leigest519/ScreenCoder.

1 INTRODUCTION

ScreenCoder addresses limitations in visual-to-code generation by decomposing perception, layout planning, and code synthesis into specialized stages. It also provides a scalable data engine and benchmarks intended to improve training and evaluation for UI-to-code models.

  • Text-only code generation requires verbose prompts for structure and styling, struggles with fine-grained visual details, and diverges from workflows that begin with visual sketches.Source: §1 · p. 2
  • Current MLLMs struggle with UI-to-code because they must jointly perform visual understanding, structural layout planning, and domain-specific code synthesis.These difficulties produce recurring perception and planning errors.Source: §1 · p. 2
  • ScreenCoder decomposes UI-to-code generation into grounding, planning, and generation, achieving state-of-the-art layout fidelity, structural coherence, and generation quality.The framework assigns visual localization, hierarchical layout construction, and HTML/CSS synthesis to separate agents.Source: §1 · p. 2
  • ScreenCoder also serves as a scalable data engine for creating high-quality image-code pairs and improving open-source MLLMs through supervised fine-tuning and reinforcement learning.The framework generates Screen-10K from filtered webpages for model training.Source: §1 · p. 2
  • Screen-10K contains 10,000 high-quality image-code pairs filtered from an initial crawl of 50,000 webpages.Source: §1 · p. 2
  • ScreenBench contains 1,000 contemporary web designs and is intended to provide a more accurate measure of model performance on real-world tasks.Source: §1 · pp. 2–3

2 RELATED WORK

Related work has advanced multimodal reasoning and visual-to-code generation, but existing systems still lack strong spatial, hierarchical, and domain-specific structure. ScreenCoder responds with interpretable modular decomposition and realistic data resources.

2.1 MULTIMODAL LARGE LANGUAGE MODELS

  • Modern MLLMs support complex multimodal tasks but struggle with UI-to-code synthesis because they lack spatial-layout and hierarchical-planning inductive biases.Source: §2.1 · p. 3

2.2 VISUAL-TO-CODE GENERATION

  • Prior visual-to-code methods progressed from DSL generation toward HTML/CSS, component recognition, layout understanding, interaction awareness, and multi-page generation.Source: §2.2 · p. 3
  • Existing approaches often remain brittle, depend on synthetic data or heuristic segmentation, and lack interpretability for jointly modeling visual semantics, layouts, and coding patterns.Source: §2.2 · p. 3
  • ScreenCoder differs by decomposing UI-to-code generation into grounding, planning, and generation while integrating domain-specific priors and scalable realistic image-code data.Source: §2.2 · p. 3

3 MOTIVATION: WHY MLLMS FAIL AT UI-TO-CODE GENERATION

The paper attributes end-to-end MLLM failures on UI-to-code generation to separate perception and planning problems that overload a monolithic model. This motivates specialized agents with injected front-end knowledge.

  • Perception failures include omitted elements, distorted attributes or text, incorrect colors, and misidentified component types.Source: §3 · p. 3, Figure 2 · p. 4
  • Planning failures include misplaced components and flat, hierarchically incoherent layouts that fail to capture nested DOM-like structure.Source: §3 · p. 3, Figure 2 · p. 4
  • The task overloads one model with granular perception, spatial planning, structured code synthesis, and front-end domain knowledge.Source: §3 · pp. 3–4
  • ScreenCoder separates grounding, planning, and generation so agents can specialize and use domain knowledge at the stage addressing each failure mode.Source: §3 · p. 4

4 METHOD

ScreenCoder uses specialized agents to ground UI components, construct a hierarchical layout, generate code, and restore visual assets. The pipeline combines semantic localization, deterministic structural planning, adaptive synthesis, and placeholder matching.

4 METHOD

  • ScreenCoder sequentially assigns grounding, planning, and generation to specialized agents that coordinate visual understanding, structural reasoning, and high-fidelity code synthesis.The overall framework is illustrated in Figure 3.Source: §4 · p. 4, Figure 3 · p. 5

4.1 GROUNDING AGENT: OVERCOMING PERCEPTION ERRORS

  • The Grounding Agent uses an MLLM to locate and label UI regions, returning bounding boxes that can be queried and manipulated through natural language.Text-guided labels make the grounding stage extensible to new UI concepts.Source: §4.1 · p. 5
  • Grounding robustness is improved with class-specific NMS, spatial-prior fallback recovery, and inference of the largest non-overlapping primary content region.The resulting layout dictionary provides the semantic and spatial foundation for planning.Source: §4.1 · p. 5

4.2 PLANNING AGENT: CORRECTING PLANNING ERRORS

  • The Planning Agent deterministically maps bounding boxes into a DOM-like layout tree, converting pixel coordinates to responsive percentages and using CSS Grid for nested regions.This trades unconstrained generative flexibility for structural integrity and predictability.Source: §4.2 · pp. 5–6

4.3 GENERATION AGENT: HIGH-FIDELITY CODE SYNTHESIS

  • The Generation Agent traverses the layout tree and uses adaptive prompts containing semantic labels, structural context, and optional user instructions to assemble HTML and CSS.Source: §4.3 · p. 6

4.4 PLACEHOLDER MAPPING

  • Placeholder mapping extracts visual elements, partitions them by planned regions, solves CIoU-based Hungarian matching, and inserts matched image patches into the generated code.A localized affine transformation corrects minor rendering discrepancies before assignment.Source: §4.4 · p. 6

5 ENHANCING MLLMS WITH SCALABLE DATA GENERATION AND DUAL-STAGE POST-TRAINING

ScreenCoder addresses noisy raw web data by generating a curated image-code dataset and using it for dual-stage post-training. Reinforcement learning further optimizes visual fidelity through rendered-image similarity.

  • 10,000 curated image-code pairs from 50,000 crawled webpages form Screen-10K, reducing the noise and instability of raw web-data training.The dataset supports a two-stage pipeline: supervised fine-tuning followed by reinforcement learning.Source: §5 · pp. 6–7
  • SFT uses 9,000 pairs to align visual understanding with code syntax, while the remaining 1,000 pairs support reinforcement learning for higher visual fidelity.Source: §5 · p. 7
  • GRPO optimizes the policy to maximize expected reward over the reinforcement-learning dataset, with x as the input image and y as generated code.Source: §5 · p. 7
  • The reward is the negative MSE between the source screenshot and the rendered output, so maximizing reward minimizes pixel-level differences.This provides a holistic signal for visual replication.Source: §5 · p. 7

6 EXPERIMENTS

Experiments evaluate ScreenCoder’s visual and semantic fidelity and its data-engine role across ScreenBench and Design2Code. The framework surpasses open-source baselines, while qualitative and ablation results clarify its advantages and training contributions.

6.1 EXPERIMENTAL SETUP

  • ScreenBench contains 1,000 contemporary image-code pairs with complex nested layouts, complementing Design2Code’s 484 older samples and structural limitations.Source: §6.1 · pp. 7–8
  • Evaluation combines CLIP similarity with OCR-based measures of block reproduction, textual consistency, spatial alignment, and color similarity.Source: §6.1 · p. 8
  • The study compares proprietary and open-source MLLMs alongside specialized UI-to-code methods, using Qwen2.5-VL-32B as ScreenCoder’s base model.Source: §6.1 · p. 8

6.2 MAIN RESULTS

  • ScreenCoder’s agentic model achieves state-of-the-art ScreenBench performance with a Block score of 0.755 and surpasses all open-source baselines.Its fine-tuned variant achieves second-best results on many metrics and approaches closed-source systems.Source: §6.2 · p. 8

6.3 QUALITATIVE ANALYSIS

  • Figure 4 shows end-to-end MLLMs producing distorted layouts and incorrect component arrangements, whereas ScreenCoder closely matches the target website’s appearance and organization.Source: Figure 4 · p. 8, §6.3 · p. 9

6.4 ABLATION STUDY

  • SFT substantially improves all metrics, especially Position, and RL adds incremental gains that produce the final top-performing results.Source: §6.4 · p. 9, Table 2 · p. 9

7 DISCUSSION

The discussion presents ScreenCoder as an interactive, configurable workflow rather than a fixed one-shot generator. Its modularity supports feedback at intermediate stages, while test-time scaling trades computation for fidelity.

  • Users can adjust the layout tree or re-prompt components without restarting the full pipeline because grounding, planning, and generation are disentangled.Source: §7 · p. 9
  • Test-time scaling lets users choose smaller models for faster, lower-fidelity drafts or larger models for high-fidelity production-ready code.High-quality generation takes tens of seconds, which the authors frame as acceptable for workflow acceleration.Source: §7 · p. 9

8 CONCLUSION

ScreenCoder combines modular multi-agent UI-to-code generation with a scalable data engine and dual-stage post-training. Experiments support its use for front-end automation and multimodal program synthesis.

  • ScreenCoder addresses end-to-end model limitations through modular generation and improves MLLMs using supervised fine-tuning and reinforcement learning.Source: §8 · p. 9
  • The reported outcome is state-of-the-art visual fidelity and code correctness, with a foundation for future multimodal program synthesis research.Source: §8 · p. 9

ETHICAL STATEMENTS

The study reports compliance with the ICLR Code of Ethics and states that it introduces no new ethical risks.

  • The research followed ethical standards for privacy, consent, and responsible AI throughout data collection and model development.Source: ETHICAL STATEMENTS · p. 10
  • The authors report that the study introduces no new ethical risks to the best of their knowledge.Source: ETHICAL STATEMENTS · p. 10

REPRODUCIBILITY STATEMENT

The paper provides implementation resources and evaluates ScreenCoder through human visual-fidelity judgments, workflow-usefulness testing, and qualitative comparisons. These evaluations report stronger fidelity, faster development, and higher-quality outputs than GPT-4o-based controls or leading baselines.

REPRODUCIBILITY STATEMENT

  • The paper makes its implementation, visual-mapping algorithm, agent prompts, and training procedure available for reproducibility.Source: REPRODUCIBILITY STATEMENT · p. 10

A.1 PAIRWISE COMPARISON OF VISUAL FIDELITY

  • In visual-fidelity comparisons, human annotators judged ScreenCoder’s outputs superior to GPT-4o’s in 65% of cases and inferior in 11%.Source: §A.1 · p. 13, Table 3 · p. 13

A.2 WORKFLOW USEFULNESS STUDY

  • Developers using ScreenCoder completed tasks 2.2 times faster than the control group, averaging 8.5 versus 18.7 minutes.All ScreenCoder participants finished within the time limit, while two control-group tasks timed out.Source: §A.2 · p. 13, Table 4 · p. 14
  • ScreenCoder users achieved an average UI-similarity score of 4.6/5.0 versus 3.4/5.0 for controls, with inter-judge Pearson correlation of 0.78.Source: §A.2 · p. 13, Table 4 · p. 14

B ADDITIONAL QUALITATIVE COMPARISONS

C.1 PROMPT TEMPLATE

  • Prompt templates used by the agents are presented in Figures 13 and 14.Source: §C.1 · p. 14

C.2 TRAINING DETAILS

The training pipeline fine-tunes a base model on Screen-10K in two stages, using supervised fine-tuning followed by reinforcement learning with visual-fidelity rewards.

  • The model is fine-tuned on 9,000 Screen-10K samples during SFT, then trained on the remaining 1,000 samples with GRPO reinforcement learning.Training uses the Llama Factory codebase on 16 NVIDIA A100 GPUs.Source: §C.2 · p. 14
  • The SFT stage uses AdamW with a cosine learning-rate schedule, peak learning rate 2 × 10^-5, weight decay 0.01, and 10% warmup.Source: §C.2 · p. 14
  • The appendix supplies qualitative comparisons across additional baseline figures, extending the visual evaluation of the method.Source: Figure 6 · p. 15, Figure 7 · p. 15, Figure 8 · p. 16
  • The reinforcement-learning reward is based on negative mean squared error between rendered output and the ground-truth image, directly optimizing visual fidelity.Source: §C.2 · pp. 14, 18
Loading 2507.22827v2…