Skip to content

How to turn an image into code with AI: the 3 levels that change the result

Image only, image plus prompt, or image, prompt and design system: what each level gets you in Claude Code and Codex, and the screenshot loop that closes the gap.

Ramon Gomes 16 min read Level: Beginner

Also available in: Español, Français, Português

When I started building screens with an AI agentProgram that uses a language model to choose actions, call tools and repeat the loop until a task is done, with little human input., I did the obvious thing: pasted the screenshot and wrote "make it like this". It worked well enough to fool me. The screen came out close, but with a gray that didn't exist in the project, a button with a different border radius from the others and no error state. Every fix afterward cost more than the first version.

In a test on my personal CRM, I compared two routes for the same CSV import screen. In the first, the screenshot went straight to Codex. In the second, another model described the image in detail, I turned the description into a briefing with the project rules, and only then did Codex build it. The second run came out faithful to the reference, and cheaper. This post explains why, in three levels, and how to set up each one in Claude, Codex or any coding agent.

Why the Image Alone Isn't Enough

The model doesn't see the screen the way you do. Anthropic explains that the image is split into 28 by 28 pixel blocks, and each block becomes a visual token: a 1000 by 1000 pixel image costs 1,296 tokens (Anthropic, vision docs). An image larger than the model's limit gets scaled down before it arrives: 1,568 pixels on the long side for most models, 2,576 pixels for the newest ones. A screenshot of a wide monitor, with tiny text, reaches the model already shrunk.

And even when the model sees well, it doesn't know what you didn't show. The screenshot doesn't say what color the --color-accent-500 token is, whether that card already exists as a component, what happens when the list is empty or how it behaves on a phone.

Academic research shows the same thing. Design2Code, a benchmark with 484 real web pages, concluded that "models mostly lag in recalling visual elements from the input webpages and generating correct layout designs" (Si et al., NAACL 2025). In the first version of the study, from 2024, pages generated by GPT-4V were already judged able to replace the original in 49% of cases (v1, 2024). In other words: it works a good part of the time, and the other half you don't know which detail went wrong until you look carefully.

Construction site table with a printed photo of a building front, a pencil floor plan, a tile sample board and color cards
The photo of the front shows what you want. The floor plan gives the measurements. The sample board says what to build it with. No good builder works from the photo alone.

The Three Levels, Side by Side

Level 1: just the image Level 2: image and prompt Level 3: image, prompt and design system
What you send the screenshot the screenshot and a text with goal, area, stack, states and constraints everything from level 2 plus the project's tokens and components
What comes back a screen that looks close, guessed values a screen with the right behavior, visuals still approximate a screen with the project's pieces and colors
Components made up made up, but in the right stack the ones that already exist
States (empty, error, loading) only the ones in the screenshot the ones you asked for the ones you asked for, in the project's pattern
Rework high medium low
When to use throwaway prototype, quick idea project with no design system any screen headed to production
The three levels of context when generating a screen from an image: just the image, image with prompt, and image with prompt and design system

Level 1: Just the Image

This is the "make it like this" everyone has tried. Claude Code takes an image dragged into the window, pasted with Ctrl+V or given as a file path in the prompt (Claude Code, common workflows). In Codex, the command line takes the image through the -i flag, and the app lets you drag the image into the text box (OpenAI, image inputs in Codex).

bash
codex -i import-screen.png "build this screen"

What usually comes back:

  • Guessed colors and spacing. The model estimates the hex from the pixels, and you get a similar shade, not the project's.
  • New components. The Figma team says it plainly: without the component reference, the agent "will likely create a new component based on the screenshot" (Figma, 2025).
  • Only the state in the screenshot. If the image shows a full list, the empty list doesn't exist in the code.
  • Text copied as hardcoded data. The sample names in the screenshot end up as text in the JSX.

For a throwaway prototype, that's enough. For production, it's where the rework starts.

Level 2: Image Plus a Real Prompt

The Codex image docs sum up what a good prompt needs: "Name what the image shows, point to the area that matters, and state the output and constraints." (OpenAI). The Claude Code best practices guide says the same and gives an example I like, because it asks for more than the layout: "build the settings page from the mockup. be ambitious: empty and error states, the save flow wired up, keyboard navigation, not just the layout" (Anthropic, Claude Code best practices).

In practice, a level 2 prompt has five parts:

  1. What the screen is and who uses it. "CSV customer import screen, used once a month by the account owner."
  2. The area that matters. "Ignore the sidebar and the header, they already exist. Build only the main content."
  3. Stack and place in the project. "React with TypeScript and Tailwind. The page goes in src/pages/import.tsx, following the pattern in src/pages/customers.tsx."
  4. States and behavior. "Empty file, file with a column error, uploading, success. The button stays disabled until a file is chosen."
  5. Constraints. "No new dependencies. Don't touch routes. Visible text goes through i18n."
text
[image: import-screen.png]

CSV customer import screen. Build only the main content:
the sidebar and the header already exist.

Stack: React + TypeScript + Tailwind. New file at src/pages/import.tsx,
following the pattern in src/pages/customers.tsx.

States: no file, invalid file (show which columns are missing),
uploading, success with the number of rows imported.

Constraints: no new dependencies, don't touch routes, text through i18n.
Before you start, ask me about anything ambiguous in the image.

Two things in that example have research behind them. In Design2Code, adding the text that appears on the page to the prompt, and asking the model to review its own code against the reference, both improved the result in human evaluation compared with the direct prompt (Si et al.). And in Sketch2Code, which evaluated ten models generating pages from sketches, UX experts showed "a significant preference for proactive question-asking over passive feedback reception" (Li et al., 2024). That's why the last line of the prompt asks it to ask first.

Level 3: Image, Prompt and Design System

To the agent, a design systemSet of components, color and spacing tokens and usage rules a team shares so every screen follows the same look and behavior. is the answer to the questions the screenshot can't answer: which color, which spacing, which component to use. Level 3 hands that over in a form it can read.

Tokens. The color, typography, spacing and radius variables. Since October 2025 there's a stable, vendor-neutral format for them, the 2025.10 specification from the W3C Design Tokens group, with support for light and dark themes and multiple brands (W3C, 2025). It doesn't have to be in that format to help: the one for this site is a Markdown table that points to the CSS, and its most important rule fits in one line: "never write a hex value directly in a component".

Components. What already exists and when to use each one. If the project has Storybook, the catalog is ready; if it uses shadcn/ui, the agent already knows a good part of the pieces.

The path to the agent. There are three ways, from simplest to most integrated:

  • A project instructions file (CLAUDE.md, AGENTS.md) that points to the design system document. The agent reads it on its own every session.
  • Figma's MCP server. Instead of the screenshot, the agent gets the name of the variable used in each element and, with Code Connect, the exact path of the component in the code. Figma says this "can make generated code more precise" and uses fewer tokens (Figma, 2025; server guide).
  • Tools built around the design system. Vercel's v0 uses a component registry: "A registry is a distribution specification designed to pass context from your design system to AI Models." (v0). Claude Design, which Anthropic launched in April 2026, builds the team's design system by reading the code and design files at the start, and hands off a package for Claude Code to implement (Anthropic, 2026).

In my CRM, level 3 became a base prompt file. The reference screens are generated with labeled blocks (SCREEN, LAYOUT, CONTENT) instead of running paragraphs, an AVOID list with the bad habits we don't want, and the image generator's native size, because a non-native size crops the edges. The same file carries the project's visual rules, and the spec that comes out of it goes along with the image to the agent that builds the screen.

markdown
## Design system (excerpt from the project instructions file)
- Colors: only var(--color-*) or the Tailwind class that points to the token. Never hex.
- Primary button: <Button variant="primary">. Don't create a new button.
- Card: <Card>, radius --radius-lg, border --color-border.
- Spacing in multiples of 4 px. Lucide icons, 16 px.
- Every screen has a loading state and an error state.

The Loop That Settles It: The Agent Looking at the Finished Screen

Level 3 takes care of what goes in. What comes out still needs checking. The Chrome team described the problem like this: coding agents "are not able to see what the code they generate actually does when it runs in the browser. They're effectively programming with a blindfold on." (Chrome for Developers, 2025).

The fix is to give it eyes. The Claude Code guide lists, among the possible checks, "A browser screenshot next to the mockup", and suggests asking for evidence: the command it ran and the output, or the screenshot (Anthropic). The reason is on the same page: "Claude stops when the work looks done." Codex does the comparison with two images at once, codex --image before.png,after.png, and the example in its own docs ends with "Verify the result with a new screenshot."

The review loop: the reference goes to the agent, it generates the screen, takes a screenshot, compares it with the reference and fixes it until they match

For the screenshot to happen on its own, the agent needs a browser:

In my workflow, the check became its own step. One tool generates the reference image, another reads the image and returns a verdict with what blocks and what's just a note, and a redo only happens when something blocks, two times at most. I measured it: generation takes about 75 seconds and the check about 82. That's cheap next to a round of fine-tuningFurther training of an existing model on your own examples to adjust style, format or specialty. It changes the model's weights, unlike just editing the prompt. done by hand.

Hand holding a paint sample card against a freshly painted wall, with the roller resting on the open can
A good painter holds the sample card to the wall before pulling the tape. The agent does the same with the screenshot next to the mockup.

How to Pass the Image in Each Tool

Tool How to send the image Where the design system goes
Claude Code drag, paste (Ctrl+V; Alt+V on Windows) or file path CLAUDE.md and the document it points to; Figma's MCP server
Codex (CLI) codex -i screen.png "..."; several, comma separated AGENTS.md; Figma's MCP server
Codex (app) drag while holding Shift the repository's AGENTS.md
Claude Design prompt, images, documents or the code itself builds the design system at the start and passes it to Claude Code
v0 attachment in the chat component registry
Google Stitch image or text, generates the interface theme and style set in the tool itself

The difference between tools matters less than the difference between levels. An average agent at level 3 delivers a better screen than the best model at level 1.

Pitfalls

Cartoon: a developer proudly shows a robot a drawing of a neatly aligned screen; in the next panel, the robot confidently hands back a screen that looks similar but is crooked, with one element spilling off the edge, and the developer facepalms
Almost the same. The buttons just changed size, the colors swapped places and one part spilled out. Nothing a design system and a screenshot can't fix.
  • A screenshot of the whole monitor. The image gets scaled down and the small text disappears. Crop to the area.
  • Only the desktop version. If mobile matters, send both screenshots or describe the behavior in the prompt.
  • Accessibility isn't in the screenshot. Contrast, focus order and screen reader labels don't show up in an image. Ask for them in the prompt and check with an automated test (axe, Lighthouse).
  • Screenshot data becomes hardcoded text. Say the names are samples and where the real data comes from.
  • Accepting the first version. The Claude Code guide is blunt about why: the agent stops when the work looks done. Without a check, "looks" is the bar.
  • Someone else's image. A screenshot of another company's site is layout inspiration, not a mold. Other people's brand, illustrations and copy don't go into your product.

If you want to go beyond the agent and understand why a design system works, two books still hold up: Design Systems, by Alla Kholmatova (Smashing Magazine, 2017), and Atomic Design, by Brad Frost (2016), which organizes the interface into atoms, molecules and organisms, a split the agent also understands well.

If the idea is to go from sketch to product in one go, read about spec driven development, which is level 2 applied to the whole project, and about tests and types in the age of AI, which is the review loop applied to code. And to see the path that brought us here, the post on the future of vibe coding.

Frequently Asked Questions

Can AI turn an image into HTML and CSS code?

Yes. Claude Code, Codex, Cursor, v0 and others take the image and return HTML, CSS, React or whatever stack you ask for. Quality depends on context: the image alone gets you a screen that looks close; with a prompt and a design system, it gets you a screen that belongs to your project.

Which AI is best for building a screen from an image?

It matters less than it seems. Frontier models read images well; what separates a good result from a bad one is what goes with the image: the prompt with states and constraints, the tokens and components, and the screenshot review loop.

What should I write in the prompt along with the image?

What the screen is, the area that matters, the stack and the reference file, the states (empty, error, loading, success) and the constraints (no new dependencies, don't touch routes). Also ask the agent to raise anything ambiguous before it starts.

Do I need a design system to use level 3?

It doesn't have to be a full design system. A table with the colors, spacing, typography and the list of existing components already changes the result. What matters is that it lives in a file the agent reads, like CLAUDE.md or AGENTS.md.

How does the agent check whether the screen matches the image?

With a browser it controls, through Playwright MCP or Chrome DevTools MCP. It opens the screen, takes a screenshot and compares it with the reference; you ask for the screenshot as proof before you accept.

What's the ideal image size to send to Claude or Codex?

Cropped to the area that matters, as PNG, without heavy compression. Claude scales down images above 1,568 pixels on the long side for most models (2,576 for the newest), so a huge screenshot doesn't gain detail, it only loses it.

Does Figma really help, or is the screenshot enough?

It helps when the design lives in Figma with variables and components. Through the MCP server, the agent gets the token name and the component's path in the code instead of guessing from pixels.

References

Source: https://ramongomessilva.com.br/blog/image-to-code-with-ai · Accessed on December 02, 2026

Share Share on LinkedIn Share on X
Cite this article

Ready-made reference, with today as the access date.

ABNT

Brazilian standard (NBR 6023). Use it in theses and academic papers submitted in Brazil.

GOMES, Ramon. How to turn an image into code with AI: the 3 levels that change the result. Ramon Gomes, 15 nov. 2026. Disponível em: https://ramongomessilva.com.br/blog/image-to-code-with-ai. Acesso em: 2 dez. 2026.

APA

American Psychological Association style. Common in scientific papers and journals, especially in the social, behavioral and health sciences.

Gomes, R. (2026, November 15). How to turn an image into code with AI: the 3 levels that change the result. Ramon Gomes. https://ramongomessilva.com.br/blog/image-to-code-with-ai

BibTeX

Format for LaTeX users (Overleaf, for example). Paste it into your .bib file or import it into Zotero or Mendeley.

@online{gomes2026imagetocode,
  author = {Gomes, Ramon},
  title = {{How to turn an image into code with AI: the 3 levels that change the result}},
  organization = {Ramon Gomes},
  year = {2026},
  month = nov,
  date = {2026-11-15},
  url = {https://ramongomessilva.com.br/blog/image-to-code-with-ai},
  urldate = {2026-12-02}
}
Found a mistake?

Wrong fact, broken link, outdated information: tell me and I will fix it.

10 to 2,000 characters. If you can, point to the right source.

Only so I can reply. It never shows on any page of the site.

Written by

Ramon Gomes

Software Engineer

Full stack software engineer. I like taking a messy problem, listening to the people who live with it and shipping something that holds up day to day. These days I split my time between my own products, applied AI and client work.

Available for projects

Need Something Like This Built?

I build websites, systems, apps and AI automations, from design to deploy. Tell me what you need or see what I offer.

Related Articles