Abstract
UI-to-code technology has streamlined the front-end development process, reducing repetitive tasks for engineers. prior research mainly use design prototypes as inputs, with the effectiveness of the generated code heavily dependent on these prototypes' quality, leading to compromised robustness. Moreover, these approaches also exhibit shortcomings in code quality, including issues such as disorganized UI structures and the inability to support responsive layouts. To address these challenges, we introduce Prototype2Code, which achieves end-to-end front-end code generation with business demands. For Prototype2Code, we incorporate design linting into the workflow, addressing the detection of fragmented elements and perceptual groups, enhancing the robustness of the generated outcomes. By optimizing the hierarchical structure and intelligently recognizing UI element types, Prototype2Code generates code that is more readable and structurally clearer. To meet responsive design requirements, Prototype2Code primarily supports flexbox layout model, ensuring code compatibility across various device sizes. To validate the efficacy, we compare Prototype2Code with the commercial code generation platform CodeFun and Screenshot-to-code based on GPT-4 with vision. Employing structural similarity index measure (SSIM), peak signal-to-noise ratio (PSNR), and mean squared error (MSE) for visual similarity assessment, Prototype2Code's rendered UI effects align most closely with the design prototypes, exhibiting the minimal errors. We also conduct a user study with five experienced front-end engineers, inviting them to review and revise code generated by the three methods. As a result, Prototype2Code surpasses other methods in readability, usability, and maintainability, better meeting the business needs of industrial development.
TL;DR
Prototype2Code is a new end-to-end pipeline that transforms UI design prototypes (like those from Figma or Sketch) into high-quality, responsive front-end code. By integrating "design linting" to fix messy design files and using a hybrid approach of Graph Neural Networks (GNNs) and Large Language Models (LLMs), it generates code that is more readable, maintainable, and visually accurate than current commercial or AI-based alternatives.
What Problem Does This Paper Address?
The "UI-to-code" dream—where a designer’s mockup instantly becomes a working website—has long been hampered by the "garbage in, garbage out" principle. Professional design files are often messy: an icon might be composed of three separate, unlinked vector arcs ("fragmented elements"), or a group of items that look like a "card" might not be grouped at all in the file’s layer hierarchy ("perceptual grouping").
Existing tools often fail in two ways:
- Structural Chaos: They produce "div soup"—disorganized, non-semantic HTML that is a nightmare for engineers to maintain.
- Lack of Responsiveness: Most tools generate absolute-positioned code that breaks the moment you change the screen size.
Prototype2Code tackles these issues by cleaning up the design data before generating code and prioritizing a responsive layout model.
Methods
The authors propose a four-stage workflow:
- Prototype Linting: Before coding starts, the system "lints" the design. It uses a Graph Neural Network (GNN) to detect fragmented elements that should be merged and a ResNet-50 based detector to identify functional groups like toolbars, cards, and list items.
- UI Layout Tree Construction: The system discards the original, often messy layer hierarchy and rebuilds it based on physical containment. Crucially, it uses a recursive algorithm to segment the UI into rows and columns, facilitating a Flexbox-based layout rather than absolute positioning.
- UI Element Recognition: To give the code semantic meaning (e.g., naming a class
.buttoninstead of.div123), the system uses a GNN. This model combines visual features (extracted via ResNet-50) with spatial features to classify elements into 25 different types. - Hybrid Code Generation:
- HTML: Generated directly from the cleaned-up layout tree to ensure structural integrity.
- CSS: Generated by GPT-4. The authors feed the LLM specific style data from the Figma API and "role-play" it as a senior developer to produce clean, reusable styles.
Key Insights and Ideas
- Structure Over Raw Vision: While tools like GPT-4 with Vision (GPT-4V) are impressive, they often "hallucinate" layouts because they only see pixels. Prototype2Code proves that multimodal input (visual pixels + underlying metadata from design tools) is essential for industrial-grade code.
- The Power of Flexbox: By forcing the layout into a row/column segmentation during the tree construction phase, the system inherently supports responsive design. This is a significant leap over tools that rely on
position: absolute. - Linting as a Prerequisite: The "Aha!" moment here is treating design files as "code with bugs." By fixing fragmented layers and missing groups before the generation phase, the downstream LLM has a much easier time producing coherent styles.
Key Results
The authors compared Prototype2Code against CodeFun (a commercial platform) and Screenshot-to-code (based on GPT-4V).
- Visual Fidelity: Prototype2Code achieved a Structural Similarity Index (SSIM) of 0.91, significantly higher than CodeFun (0.64) and GPT-4V (0.58). It also showed the lowest Mean Squared Error (MSE), meaning the rendered code looked most like the original design.
- Engineer Approval: In a user study with five professional front-end engineers, Prototype2Code swept the board. It scored 4.4/5 for availability (meaning it required the least manual fixing) compared to 3.0 for CodeFun and 2.6 for GPT-4V.
- Readability: Engineers found the generated code significantly easier to read due to the semantic class naming and clean Flexbox structure.
Limitations and Future Work
Despite its strengths, the paper notes a few areas for growth:
- Static Only: The system currently generates static HTML/CSS. It cannot yet handle "logic" (like what happens when you click a button) or state management.
- Framework Support: It produces native HTML/CSS, but modern industrial development often requires React, Vue, or Tailwind CSS.
- Interaction Design: The current model doesn't recognize complex interactive elements like hover states or multi-state components (e.g., a toggle switch), often defaulting to treating them as simple images.
Summary updated