跪拜 Guibai
← All articles
Frontend · Backend · AI Programming

Figma-to-Pixel Autopilot: A Skill That Makes AI Verify Its Own Front-End Work

By 不一样的少年_ ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The cost of AI-assisted front-end work now shifts from code generation to pixel-perfect verification; this workflow removes the human from that loop, turning Figma-to-page into an autonomous verify-and-fix pipeline that runs while the developer does something else.

Summary

Design-to-page AI tools have been generating code for a while, but the last mile remains manual: someone compares the browser against the Figma file, spots a 2px offset, and types yet another prompt. This Skill closes that loop by giving the agent four abilities: read design nodes through Figma MCP, run a Chrome-based browser (EGO Lite) with real login state to take screenshots under locked viewport and DPR, align and overlay those screenshots with Sharp to produce diff and overlay images, and inspect the live DOM via getBoundingClientRect() and elementsFromPoint() before changing any CSS.

The workflow encodes three rules that keep agents from going in circles: separate layout scaling from asset export scaling (a 360px dev baseline vs 720px design sheet means dividing CSS values by 2 but exporting at 1x), split layers into DOM vs. image based on whether content changes and whether it needs interaction, and never blind-tune top/left from diff images—first measure the box model, check for overflow:hidden ancestors, and look for invisible overlays. After each code change, the agent screenshots again and re-diffs until the overlay shows no mismatch, with a stop rule that forces it to ask for more context after two failed iterations.

The author has used this internally for about six months and shares no source code, describing it as a workflow recipe that any team can adapt to its own stack by feeding the rules to a coding agent like Claude Code or Cursor.

Takeaways
— The Skill requires four parts: a coding agent, Figma MCP, a Chrome-based browser with login state (EGO Lite), and Sharp for pixel comparison.
— It distinguishes layout scaling (CSS) from asset export scaling: for a 360px dev baseline, a 720px design sheet means writing CSS at half the measured size and exporting assets at 1x to get the equivalent of 2x images.
— Layer-splitting rule: dynamic text and interactive regions go in real DOM; complex visuals go to exported images; a composite of image background + DOM overlay works for reward cards and similar components.
— Visual acceptance locks viewport, DPR, fonts, and page state before taking a screenshot, then uses Sharp to resize both images to identical dimensions before generating overlay and diff images.
— Diff images are necessary because an AI looking at two separate images cannot spot a 2px offset; overlay and diff images turn pixel deviations into obvious red regions.
— When a diff shows an issue, the agent must inspect the DOM box model with getBoundingClientRect(), check for overflow:hidden ancestors, and use elementsFromPoint() to detect overlays before applying any style change.
— A stop rule: after two rounds of failed corrections, the agent must stop and ask for missing context instead of continuing to tweak pixel values.
— The author has used this workflow internally for about six months and recommends teams build their own Skill by writing rules for a coding agent rather than reusing a fixed script.
Conclusions

The real value here is making the AI's loop self-verifying; the hard part of AI coding isn't generating code but knowing when it's right, and the screenshot-diff loop gives the agent a concrete mechanism to decide that.

The rule to never tune styles without inspecting the DOM mirrors what a human developer does with DevTools; encoding that discipline prevents the classic 'fix one pixel, break layout' cascade, which is the main reason AI-generated pages often spiral.

The workflow deliberately avoids shipping a reusable Skill file, arguing that any team can generate it by stating rules to a coding agent; this reflects how prompting tools are evolving—the rules themselves become the product.

Concepts & terms
Figma MCP
A Model Context Protocol server that lets an AI agent read Figma file structure, node attributes, and export assets directly, instead of relying on screenshots.
DPR (Device Pixel Ratio)
The ratio of physical pixels to CSS pixels on a screen; at DPR 2, a CSS 40px element will look sharp only if the underlying image is at least 80 physical pixels.
Pixel diffing
A technique that overlays two images and highlights differing pixels, producing an overlay or diff image to pinpoint layout deviations.
From the discussion

Pixel-perfect 100% restoration fails in practice, because too many constraints make the Skill clumsy, token-heavy, and unstable between runs. The workable alternative is an overlay loop where the agent pairs the screenshot and the mockup through Sharp and self-corrects round after round, with one setup reporting roughly 98% fidelity. Without an acceptance or comparison step, the agent declares victory too early and still drags a human through several UI fix rounds. Missing design mockups are treated as non-blocking: the agent freestyles or runs a /frontend-design command.

— 100% pixel-perfect restoration breaks down in practice: adding constraints makes the flow clumsy, devours tokens, and yields unstable output across runs.
— A Sharp-based overlay diff, treating the screenshot and design like an X-ray, gives the agent a direct comparison and lets it self-correct until an acceptable pass, with little manual tuning.
— Security restrictions and Claude's tendency to improvise in some spots keep the approach from being fully hands-off; repeated fix rounds make the per-page cost too high.
— Figma MCP alone is not enough; an output-comparison acceptance step is needed, otherwise the agent calls for human eyes prematurely and still requires multiple UI-fix cycles.
— A missing design mockup is not a blocker: the agent can free-play or run a /frontend-design beautify command.
— One implementation lands around 98% first-pass fidelity, with the remaining pixel-level defects passed back to the agent as UI bugs.
— Source code is not the bottleneck: the internal Skill is not public, so the recommended move is to feed the article to Codex or Claude Code and build a project-specific variant.
— Infrastructure-related limitations can be handled separately by provisioning a dedicated dev machine.
Featured comments
只会哈哈哈 1 likes

I did this for a while too, also directly reading Figma and wrapping it in a skill. Our requirement was 100% pixel-perfect restoration, but in the end it wasn't achieved. Adding too many constraints made it clumsy, the process was too convoluted, and tokens burned too fast. Plus, reproducing the same design every time gave unstable results. [covering face]

不一样的少年_

True, 100% restoration is pretty hard 😂 We have the agent use Sharp to stack the page screenshot and the design mockup together and inspect the differences like an X-ray. I basically do no manual adjusting; the Agent compares and fixes on its own, and if one round doesn't work, it just runs another round ~

只会哈哈哈  → 不一样的少年_

We're also stuck on security; the agent can't be used carelessly. Overall approach is similar, and Claude's restoration is pretty decent, but it improvises in some places. With repeated modifications, the cost per page ends up too high. [awkward laugh]

打工人阿景

Then here's the question: what if there's no design mockup?

不一样的少年_

No design mockup? Just freestyle it [snickering]

LGGGGG

/frontend-design, help me beautify the page.

zhao1zhihui

What's the one-pass restoration rate?

不一样的少年_

Restoration rate is about 98%; the remaining are minor pixel-level issues. Once UI files bugs, just hand them straight to the Agent to fix.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗