NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

LaTCoder: Converting Webpage Design to Code with Layout-as-Thought

Yi Gui, Zhen Li, Zhongyi Zhang, Guohao Wang, Tianpeng Lv, Gaoyang Jiang, Yi Liu, Dongping Chen, Yao Wan, Hongyu Zhang, Wenbin Jiang, Xuanhua Shi, Hai Jin

Abstract

Translating webpage mockups into functional HTML/CSS is a critical bottleneck in front-end development. While modern Multimodal Large Language Models (MLLMs) like GPT-4o demonstrate impressive code generation capabilities, they often struggle with complex, high-resolution layouts when using a monolithic generation approach. This paper introduces LaTCoder, a framework that utilizes a "Layout-as-Thought" (LaT) strategy. By decomposing designs into manageable blocks and employing a divide-and-conquer pipeline, LaTCoder significantly improves structural fidelity and visual similarity in automated design-to-code tasks.

1. Introduction

The "design-to-code" task aims to automate the translation of UI mockups into working code. Current state-of-the-art MLLMs typically attempt to generate the entire codebase in a single pass. However, for real-world webpages with intricate styles and deep DOM trees, this monolithic approach frequently results in misaligned elements and broken spatial relationships. The models lose track of global layout constraints while processing thousands of lines of code simultaneously.

2. Methodology: The LaTCoder Pipeline

LaTCoder addresses these challenges by breaking the generation process into discrete spatial "thoughts," analogous to Chain-of-Thought (CoT) reasoning in text-based LLMs.

The LaTCoder pipeline: from design division to block-wise synthesis and final assembly.

2.1 Layout-Aware Division

The first stage involves a specialized algorithm that scans the input image for solid-colored horizontal and vertical dividing lines. By integrating Optical Character Recognition (OCR), the system ensures that divisions do not bisect text elements. This process segments the design into grid-aligned bounding boxes (BBoxes).

Example of layout-aware division applied to a complex social media profile mockup.

2.2 Block-Wise Code Synthesis

Each cropped image block is processed individually by the MLLM. Using a CoT prompting strategy, the model analyzes the specific section to generate Tailwind-based HTML and CSS. This localized focus allows the model to maintain high consistency in text, color, and styling without being overwhelmed by the entire page's complexity.

2.3 Layout-Preserved Assembly

The final stage involves stitching the individual code blocks back together. LaTCoder generates two candidate versions:

  1. Absolute Positioning Assembly (APS): Hardcodes positions based on original BBox coordinates.
  2. MLLM-Based Assembly (MS): Uses the MLLM to intelligently merge blocks into a cohesive, responsive structure.

A reference-free verifier, combining pixel-level Mean Absolute Error (MAE) and semantic CLIP scores, dynamically selects the superior output.

3. Datasets and Evaluation

To rigorously test the framework, the authors utilized Design2Code-HARD (80 complex samples) and introduced CC-HARD. The latter is a newly curated dataset from Common Crawl containing 128 highly challenging samples characterized by deeper DOM trees and more unique HTML tags than existing benchmarks.

4. Key Results

Experimental results using models like GPT-4o and Gemini 1.5 Pro demonstrate the efficacy of the LaT approach:

  • Structural Fidelity: On the CC-HARD dataset, LaTCoder improved TreeBLEU (measuring DOM tree similarity) by 60% compared to direct monolithic prompting.
  • Visual Accuracy: Pixel-level differences (MAE) dropped by 43.23% when using GPT-4o within the LaTCoder framework.
  • Human Preference: In blind side-by-side tests, human annotators preferred LaTCoder's output in over 60% of cases, significantly outperforming competing methods like DCGen.

5. Discussion and Conclusion

LaTCoder demonstrates that "Divide and Conquer" is a powerful paradigm for visual tasks. While the framework drastically improves macro-layout accuracy, some challenges remain at the micro-layout level, such as the precise alignment of elements within small divs. Additionally, MLLM "laziness" during the assembly phase can occasionally lead to omitted sections. Future work will focus on refining micro-spatial awareness and developing more robust assembly prompts to ensure complete code coverage. Despite these limitations, LaTCoder represents a significant step toward reliable, automated front-end development.

Summary updated

BibTeX
@inproceedings{gui2025latcoder,
  author = {Yi Gui and Zhen Li and Zhongyi Zhang and Guohao Wang and Tianpeng Lv and Gaoyang Jiang and Yi Liu and Dongping Chen and Yao Wan and Hongyu Zhang and Wenbin Jiang and Xuanhua Shi and Hai Jin},
  title = {{LaTCoder: Converting Webpage Design to Code with Layout-as-Thought}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2025},
}
Figure