Widget2Code: From Visual Widgets to UI Code via Multimodal LLMs

Houston H. Zhang, Tao Zhang, Baoze Lin, Yuanqi Xue, Yincheng Zhu, Huan Liu, Li Gu, Linfeng Ye, Ziqiang Wang, Xinxin Zuo, Yang Wang, Yuanhao Yu, Zhixiang Chi

TL;DR

This paper formalizes Widget2Code, a novel task focused on reconstructing executable front-end code from an image of a user interface widget. To tackle the unique challenges of widgets—such as dense iconography, compact layouts, and strict spatial constraints—the authors introduce the first image-only widget dataset and propose a modular framework combining a Perceptual Agent and an end-to-end infrastructure called WidgetFactory. This approach significantly improves visual fidelity and eliminates layout overflow by incorporating icon retrieval and a browser-feedback rendering loop.

What Problem Does This Paper Address?

Automating the translation of UI designs into code (UI2Code) saves developers immense time. While prior work has successfully targeted web pages and mobile screens, app widgets have been largely ignored.

Widgets are fundamentally different from standard web pages or mobile apps:

  • High Density & Spatial Constraints: They are compact, context-free micro-interfaces that pack text, complex charts, and icons into strict bounding boxes.
  • Lack of Data: Unlike web pages (which have HTML/CSS pairs) or mobile screens (which expose view hierarchies via accessibility APIs), widget designs are typically proprietary and lack accessible markup.

When standard Multimodal Large Language Models (MLLMs) or specialized UI2Code models try to generate code for widgets, they fail dramatically. They frequently suffer from element misalignment, color inconsistencies, missing icons, and "content overflow"—where text or graphics spill outside the widget's strict boundaries.

Figure 1. Comparison across interface modalities. Web and mo- bile UIs provide rich structural and textual context that supports rule-based code mapping, whereas widgets employ dense iconog- raphy, embedded graphs, and vivid color schemes within highly constrained layouts. These stylistic and structural compactness factors pose substantial challenges for UI-to-Code reconstruction.

Methods

To solve these challenges, the authors move away from unconstrained direct code generation and propose a structured, two-level pipeline:

1. Perceptual Agent (Atomic Analysis)

Instead of asking an MLLM to write code directly from pixels, a Perceptual Agent first decomposes the widget image into structured primitives:

  • Component Extraction: An MLLM detects and categorizes bounding boxes for text, buttons, and charts.
  • Icon Retrieval: Rather than letting the model hallucinate or poorly draw icons, the system uses SigLIP embeddings to perform a coarse-to-fine visual and textual search over a library of 50,000 clean SVG icons.
  • Color Extraction: The system maps the image to a perceptually uniform color space and applies $K$-means clustering to extract the dominant color palette.
  • Reusable Component Templates: Complex elements like plots or charts are mapped to flexible, pre-defined templates that can be instantiated with custom data and styles.

2. WidgetFactory (System-Level Generation & Rendering)

The extracted attributes are fed into an infrastructure that guarantees structural control:

  • WidgetDSL: A framework-agnostic, compact Domain-Specific Language designed specifically for widgets.
  • Code Compilation: A compiler transforms the WidgetDSL into an Abstract Syntax Tree (AST), which can then be deterministically translated into multiple target frameworks (e.g., React, HTML/CSS).
  • Adaptive Rendering: To prevent content overflow, the system uses a feedback-guided binary search loop. It renders the widget in a headless browser, checks for layout violations or clipping, and iteratively adjusts the dimensions ($w, h$) until the content fits perfectly while preserving the original aspect ratio.

Datasets

Because no public widget code datasets exist, the authors built the first image-only widget benchmark:

  • The Widget2Code Dataset: 12,218 raw widget images crawled from platforms like Figma, Dribbble, and Refero, as well as mobile screenshots.
  • After deduplication and manual verification via CLIP features, they retained 2,825 high-quality widget images (1,000 used for testing, 1,825 for development).

Key Insights and Ideas

  • Specialized UI2Code Models Fail on Widgets: Models trained specifically for web pages (like Design2Code) perform worse on widgets than general-purpose MLLMs (like GPT-4o or Gemini 2.5). This is because web models rely heavily on rich hierarchical text contexts, which compact widgets lack.
  • The Power of Intermediate DSLs: Generating raw HTML/CSS directly from an image gives the LLM too many degrees of freedom, leading to verbose, unmaintainable, and broken code. Constraining the model to output a structured DSL drastically reduces hallucinations.
  • Closing the Loop with Browser Feedback: Static code generation cannot foresee how a browser engine will compute text wrapping or padding. Incorporating actual rendering feedback into an optimization loop is essential for satisfying strict spatial constraints.

Key Results

The authors evaluated their framework against state-of-the-art models using a comprehensive suite of visual-only metrics across Layout, Legibility, Style, Perception, and Geometry.

  • Perfect Geometry: Thanks to the adaptive rendering module, the proposed framework achieved a perfect Geometry score of 100.00, completely eliminating aspect ratio distortion and boundary overflow.
  • Superior Style and Layout: The framework outperformed its base model (Qwen3-VL) and all other baselines. For instance, it boosted the Layout Margin score from 64.75 to 72.15 and Style Polarity from 54.85 to 63.28.
Ablation study showing visual improvements as modules are added.

Limitations and Future Work

While the framework establishes a strong baseline, the authors note a few areas for improvement:

  • Ultra-Dense Layouts: Extremely compact micro-visualizations still pose a challenge for precise visual grounding.
  • Hallucination Reduction: Further refinements are needed in the intermediate representations to completely eliminate data invention in complex charts.
  • Dynamic Behaviors: The current work focuses purely on static widget reconstruction; extending this to support interactive or dynamic widget states is a promising direction for future research.

Summary updated

BibTeX
@inproceedings{zhang2026widget,
  author = {Houston H. Zhang and Tao Zhang and Baoze Lin and Yuanqi Xue and Yincheng Zhu and Huan Liu and Li Gu and Linfeng Ye and Ziqiang Wang and Xinxin Zuo and Yang Wang and Yuanhao Yu and Zhixiang Chi},
  title = {{Widget2Code: From Visual Widgets to UI Code via Multimodal LLMs}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=1s6hNujwpT},
}
Figure