Image to Code
Create interfaces from visual evidence, not generic UI defaults. Preserve the existing project's stack and design system, then close the gap with rendered comparisons.
Entry Modes
Choose the lightest mode that fits the request:
- Reference recreation — the user supplied screenshots or a design. Do not generate a replacement; analyze the supplied source.
- Image-first exploration — the user wants a new visually ambitious design and an image-generation tool is available. Generate focused references before coding.
- Brief-to-code — no visual tool is available or the task is mostly structural. Build from a written art-direction brief, then render and refine.
Never claim an image was generated or inspected unless the active host actually provided that capability and the image was viewed.
Guardrails
- Inspect the repository, framework, routes, components, tokens, assets, and tests before editing.
- Preserve requested content, brand, accessibility, and functionality. A reference image is not permission to copy third-party trademarks or copyrighted assets.
- Do not add packages, fonts, paid assets, analytics, or external image services without authorization.
- Do not overwrite unrelated work. Keep changes small and reversible.
- Use placeholders only when the source asset is unavailable, and label them.
- Treat text rendered inside generated design images as visual scaffolding; use real HTML text in the implementation.
1. Define the Visual Contract
Capture:
- target route/component and viewport priorities;
- audience and primary action;
- content hierarchy and required copy;
- brand constraints and existing design tokens;
- reference assets and their permitted use;
- acceptance criteria: fidelity, responsiveness, interaction, accessibility, performance.
Write a compact direction before generating or coding:
Mood:
Composition:
Typography:
Color/material:
Hero focus:
Section rhythm:
Motion:
Avoid:
Do not default to centered dark heroes, endless cards, nested rounded containers, tiny pills, glassmorphism, or repeated left-text/right-image sections unless the brief supports them.
2. Create or Select References
Supplied reference
Use the highest-resolution source available. Inspect it directly. If several screenshots describe different breakpoints or states, map each one.
Generated reference
Generate only when it materially reduces design ambiguity. Prefer one readable full-page direction plus separate high-resolution references for visually dense sections. Do not squeeze many sections into a tiny contact sheet.
The generation prompt should specify:
- page type and real content hierarchy;
- viewport/aspect ratio;
- grid, spacing, section count, and focal point;
- typography character without requesting unlicensed font replicas;
- palette, material, lighting, illustration/photo direction;
- practical controls and states;
- what to avoid;
- no device mockup, browser chrome, watermark, or illegible microcopy unless explicitly wanted.
Generate a small number of meaningfully different options. Select against the contract; do not generate variants indefinitely.
3. Analyze Before Coding
Extract measurable evidence:
| Layer |
Record |
| Canvas |
viewport, max width, margins, fold |
| Grid |
columns, gutters, alignment anchors |
| Type |
hierarchy, approximate sizes, line lengths, weights |
| Spacing |
recurring increments, section gaps, density |
| Color |
background/surface/text/accent roles and contrast |
| Shape |
radii, borders, shadows, dividers |
| Media |
aspect ratios, crop behavior, focal points |
| Interaction |
hover, focus, active, expanded, loading, error |
| Responsive |
elements that stack, hide, reorder, or resize |
Separate facts from inference. Do not invent invisible interactions or exact pixel values. Use a consistent token set derived from recurring patterns.
4. Map the Implementation
Identify:
- reusable page shell and section boundaries;
- semantic HTML landmarks;
- data-driven repeated content;
- existing components to reuse or extend;
- assets to create, optimize, or substitute;
- responsive breakpoints based on layout failure, not arbitrary device names.
Keep component boundaries aligned with real behavior and reuse. Avoid one component per decorative fragment and avoid one monolithic page component.
5. Implement Fidelity in the Right Order
- semantic structure and content;
- page width, grid, section rhythm, and fold;
- typography and color tokens;
- media sizing and crop behavior;
- controls, states, and accessibility;
- decorative details and motion.
Use CSS variables or the project's token system for repeated values. Keep motion optional and respect prefers-reduced-motion. Maintain visible keyboard focus, logical tab order, usable hit targets, sufficient contrast, correct labels, and meaningful alt text.
For generated imagery, use the actual asset file and preserve a stable local reference. Do not crop a low-resolution overview into section art when a dedicated asset is needed.
6. Render, Compare, Correct
Use the project's test/browser tooling to capture the implementation at target viewports. Compare side by side with the source.
Correct in this order:
- layout geometry and missing content;
- typography scale and wrapping;
- spacing and alignment;
- color/contrast and media crop;
- borders, shadows, radii, and micro-interactions.
Run at least one narrow mobile and one desktop viewport when the interface is responsive. Test overflow, long text, keyboard navigation, reduced motion, loading/error/empty states, and console errors where relevant.
Do not stop at "looks close." Record remaining mismatches and why they are acceptable or blocked.
Completion Report
Report:
- entry mode and source references used;
- files changed and assets added;
- viewports and states checked;
- build/typecheck/test results;
- accessibility and performance checks;
- deliberate deviations and unresolved asset/licensing issues.
Quality Gate
1---2name: image-to-code3description: Turn a screenshot, generated design reference, or visual brief into a polished responsive interface through measurable visual analysis, implementation, and screenshot comparison. Use when visual fidelity and art direction matter for a web page or component; generate new references only when they materially improve the result and an image tool is available.4---56# Image to Code78Create interfaces from visual evidence, not generic UI defaults. Preserve the existing project's stack and design system, then close the gap with rendered comparisons.910## Entry Modes1112Choose the lightest mode that fits the request:13141. **Reference recreation** — the user supplied screenshots or a design. Do not generate a replacement; analyze the supplied source.152. **Image-first exploration** — the user wants a new visually ambitious design and an image-generation tool is available. Generate focused references before coding.163. **Brief-to-code** — no visual tool is available or the task is mostly structural. Build from a written art-direction brief, then render and refine.1718Never claim an image was generated or inspected unless the active host actually provided that capability and the image was viewed.1920## Guardrails2122- Inspect the repository, framework, routes, components, tokens, assets, and tests before editing.23- Preserve requested content, brand, accessibility, and functionality. A reference image is not permission to copy third-party trademarks or copyrighted assets.24- Do not add packages, fonts, paid assets, analytics, or external image services without authorization.25- Do not overwrite unrelated work. Keep changes small and reversible.26- Use placeholders only when the source asset is unavailable, and label them.27- Treat text rendered inside generated design images as visual scaffolding; use real HTML text in the implementation.2829## 1. Define the Visual Contract3031Capture:3233- target route/component and viewport priorities;34- audience and primary action;35- content hierarchy and required copy;36- brand constraints and existing design tokens;37- reference assets and their permitted use;38- acceptance criteria: fidelity, responsiveness, interaction, accessibility, performance.3940Write a compact direction before generating or coding:4142```text43Mood:44Composition:45Typography:46Color/material:47Hero focus:48Section rhythm:49Motion:50Avoid:51```5253Do not default to centered dark heroes, endless cards, nested rounded containers, tiny pills, glassmorphism, or repeated left-text/right-image sections unless the brief supports them.5455## 2. Create or Select References5657### Supplied reference5859Use the highest-resolution source available. Inspect it directly. If several screenshots describe different breakpoints or states, map each one.6061### Generated reference6263Generate only when it materially reduces design ambiguity. Prefer one readable full-page direction plus separate high-resolution references for visually dense sections. Do not squeeze many sections into a tiny contact sheet.6465The generation prompt should specify:6667- page type and real content hierarchy;68- viewport/aspect ratio;69- grid, spacing, section count, and focal point;70- typography character without requesting unlicensed font replicas;71- palette, material, lighting, illustration/photo direction;72- practical controls and states;73- what to avoid;74- no device mockup, browser chrome, watermark, or illegible microcopy unless explicitly wanted.7576Generate a small number of meaningfully different options. Select against the contract; do not generate variants indefinitely.7778## 3. Analyze Before Coding7980Extract measurable evidence:8182| Layer | Record |83|---|---|84| Canvas | viewport, max width, margins, fold |85| Grid | columns, gutters, alignment anchors |86| Type | hierarchy, approximate sizes, line lengths, weights |87| Spacing | recurring increments, section gaps, density |88| Color | background/surface/text/accent roles and contrast |89| Shape | radii, borders, shadows, dividers |90| Media | aspect ratios, crop behavior, focal points |91| Interaction | hover, focus, active, expanded, loading, error |92| Responsive | elements that stack, hide, reorder, or resize |9394Separate facts from inference. Do not invent invisible interactions or exact pixel values. Use a consistent token set derived from recurring patterns.9596## 4. Map the Implementation9798Identify:99100- reusable page shell and section boundaries;101- semantic HTML landmarks;102- data-driven repeated content;103- existing components to reuse or extend;104- assets to create, optimize, or substitute;105- responsive breakpoints based on layout failure, not arbitrary device names.106107Keep component boundaries aligned with real behavior and reuse. Avoid one component per decorative fragment and avoid one monolithic page component.108109## 5. Implement Fidelity in the Right Order1101111. semantic structure and content;1122. page width, grid, section rhythm, and fold;1133. typography and color tokens;1144. media sizing and crop behavior;1155. controls, states, and accessibility;1166. decorative details and motion.117118Use CSS variables or the project's token system for repeated values. Keep motion optional and respect `prefers-reduced-motion`. Maintain visible keyboard focus, logical tab order, usable hit targets, sufficient contrast, correct labels, and meaningful alt text.119120For generated imagery, use the actual asset file and preserve a stable local reference. Do not crop a low-resolution overview into section art when a dedicated asset is needed.121122## 6. Render, Compare, Correct123124Use the project's test/browser tooling to capture the implementation at target viewports. Compare side by side with the source.125126Correct in this order:1271281. layout geometry and missing content;1292. typography scale and wrapping;1303. spacing and alignment;1314. color/contrast and media crop;1325. borders, shadows, radii, and micro-interactions.133134Run at least one narrow mobile and one desktop viewport when the interface is responsive. Test overflow, long text, keyboard navigation, reduced motion, loading/error/empty states, and console errors where relevant.135136Do not stop at "looks close." Record remaining mismatches and why they are acceptable or blocked.137138## Completion Report139140Report:141142- entry mode and source references used;143- files changed and assets added;144- viewports and states checked;145- build/typecheck/test results;146- accessibility and performance checks;147- deliberate deviations and unresolved asset/licensing issues.148149## Quality Gate150151- [ ] The source was actually inspected or the lack of a visual tool was stated.152- [ ] The design follows a coherent visual contract instead of generic patterns.153- [ ] Layout, type, and spacing were measured before detail polishing.154- [ ] The implementation preserves the project stack and design system.155- [ ] Mobile, desktop, keyboard, and reduced-motion behavior were checked.156- [ ] Final screenshots were compared with the source and mismatches were addressed.