Divide-and-Conquer: Generating UI Code from Screenshots

Yuxuan Wan, Chaozheng Wang, Yi Dong, Wenxuan Wang, Shuqing Li, Yintong Huo, Michael Lyu · DOI

Introduction

Converting a user interface (UI) design into functional HTML and CSS is a critical yet time-consuming step in the software development lifecycle. While Multimodal Large Language Models (MLLMs) like GPT-4o have shown promise in "coding from a screenshot," they frequently struggle with the structural complexity of real-world webpages. Researchers from The Chinese University of Hong Kong and Singapore Management University have introduced DCGen, a framework that employs a "divide-and-conquer" strategy to bridge the gap between design mockups and production-ready code.

The Challenge: Why MLLMs Fail at Full-Page Layouts

The "Design-to-Code" task requires translating a visual image into precise code. Despite their advanced reasoning capabilities, MLLMs often exhibit three types of "hallucinations" when processing full-page screenshots:

  1. Element Omission: Missing entire sections like footers or sidebars.
  2. Element Distortion: Misrepresenting the visual properties (size, color, shape) of UI components.
  3. Element Misarrangement: Incorrectly positioning elements within the layout.

The core issue is "visual overload." MLLMs are effectively "near-sighted"; they perform significantly better when focusing on small, isolated segments than when attempting to parse a high-resolution, multi-element webpage simultaneously.

The DCGen Framework: Division and Assembly

DCGen addresses these limitations by breaking the generation process into two distinct phases: Division and Assembly.

1. The Division Phase

Instead of relying on standard object detection, which often fails to capture the nested, rectangular nature of web layouts, DCGen uses a specialized image segmentation algorithm. It identifies "separation lines"—both explicit (borders) and implicit (white space)—using a dual-threshold sliding window. The image is recursively split horizontally and vertically until it is reduced to "leaf nodes," which are small, semantically meaningful UI segments.

Figure 4: DCGen recursively segments a full-page screenshot into manageable logical sections, such as the FAQ area highlighted here.

2. The Assembly Phase

After a "Leaf-solver MLLM" generates code for each segment, DCGen reassembles them using one of two methods:

  • Agent-based Assembly: A high-level MLLM acts as an architect, merging child segment code into a coherent parent structure.
  • Rule-based Assembly: A deterministic approach using CSS Grid to hard-code positions, ensuring the final layout remains perfectly aligned with the original design.

Evaluation and Datasets

To test DCGen's robustness, the researchers moved beyond synthetic datasets to real-world complexity:

  • Real-World Dataset: 348 websites from the Tranco top 500 (e.g., Amazon, Apple, Facebook).
  • Design2Code-Hard: A benchmark of 80 highly complex webpages from GitHub Pages.
  • Human Evaluation: A testing set of 111 webpages was used for both automated metrics and user studies.
Figure 6: Examples of UI components from real-world datasets like Amazon and Apple/X used to evaluate DCGen's ability to handle diverse layouts.

Key Insights and Results

The study yielded several critical findings:

  • Resolution vs. Reasoning: MLLMs do not necessarily need more "intelligence" to fix UI bugs; they need less visual noise. Cropping a "failed" section and re-feeding it to the model often results in perfect code.
  • Visual Fidelity: DCGen achieved a 15% improvement in visual similarity (via CLIP score) and an 8% boost in code similarity compared to direct prompting.
  • Human Productivity: In user studies, developers using DCGen-assisted tools completed UI tasks in 8 minutes on average, compared to 14.5 minutes for the control group—a nearly 2x speedup.

Conclusion

DCGen demonstrates that a divide-and-conquer approach significantly enhances the reliability of automated UI code generation. By reducing the visual load on MLLMs, the framework produces higher-fidelity code and serves as a powerful productivity tool for front-end developers. While challenges remain in assembly accuracy for smaller models, DCGen represents a major step toward fully automated design-to-code pipelines.

Summary updated

BibTeX
@article{wan2025divide,
  author = {Yuxuan Wan and Chaozheng Wang and Yi Dong and Wenxuan Wang and Shuqing Li and Yintong Huo and Michael Lyu},
  title = {{Divide-and-Conquer: Generating UI Code from Screenshots}},
  journal = {Proceedings of the ACM on Software Engineering},
  year = {2025},
  doi = {10.1145/3729364},
}
Figure