Back to cookbook

AI Prompt to Turn a Design Screenshot into a React Component

6 views Updated
Share

This is a React prompt for converting a design screenshot or mockup into working React component code β€” built for frontend developers who get a Figma export, a screenshot, or a reference site and need a working component fast, without hand-measuring every spacing value and color. It's aimed at ChatGPT, Claude, and Gemini's vision-capable models, which can read an attached image and describe its layout, but need explicit direction to turn that description into clean, production-usable code rather than a rough approximation.

The prompt works by having the model first describe what it sees β€” layout structure, spacing, typography, colors, and states like hover or active β€” before writing any code, which reduces guessing on details that are easy to eyeball wrong. It then asks for the component broken into logical pieces (structure, styling, props) so the output is something you can actually drop into a codebase rather than a single unreviewable block.

Models can only work from what's visible in the image, so anything not shown (like exact hex values in a low-resolution screenshot, or interaction behavior) has to be filled in with placeholders you confirm afterward β€” it's a starting point for a component, not a pixel-perfect guarantee.

Prompt template

ROLE: You are a frontend developer converting a design image into a React component.

CONTEXT: I'm attaching a design screenshot/mockup. Tech stack: [REACT VERSION, STYLING APPROACH e.g. Tailwind/CSS Modules/styled-components, COMPONENT LIBRARY IF ANY]

TASK:

  1. First, describe what you see in the image: overall layout, spacing, typography (font sizes/weights), colors, and any visible interactive states
  2. Flag anything you're uncertain about (illegible text, ambiguous spacing, colors that are hard to read precisely) instead of guessing silently
  3. Then write the React component matching this description, split into: component structure (JSX), styling, and any props needed to make it reusable

CONSTRAINTS:

  • Match the layout and spacing as closely as possible to what's visible in the image
  • Use [STYLING APPROACH] only, no inline styles unless the project convention requires it
  • Make the component accept props for any content that would realistically vary (text, images, links)
  • [ANY ADDITIONAL CONSTRAINT, e.g. must be accessible, must support dark mode]

OUTPUT FORMAT:

  1. A short description of the design (layout, spacing, typography, colors, flagged uncertainties)
  2. The complete component code in a fenced code block
  3. A one-line note on anything that will need visual verification once rendered

Example input

ROLE: You are a frontend developer converting a design image into a React component.

CONTEXT: I'm attaching a design screenshot of a pricing card. Tech stack: React 18, Tailwind CSS, no component library.

TASK:

  1. First, describe what you see in the image: overall layout, spacing, typography, colors, and any visible interactive states
  2. Flag anything you're uncertain about
  3. Then write the React component matching this description, split into: component structure (JSX), styling, and any props needed

CONSTRAINTS:

  • Match the layout and spacing as closely as possible
  • Use Tailwind CSS only, no inline styles
  • Make the component accept props for plan name, price, features list, and CTA button text

OUTPUT FORMAT:

  1. A short description of the design
  2. The complete component code in a fenced code block
  3. A one-line note on anything that will need visual verification

Example output

Design description: A vertically-stacked pricing card with rounded corners and a subtle shadow. Plan name in bold at the top, a large price below it, a bulleted feature list with checkmark icons, and a full-width button at the bottom. Uncertain: exact shade of the accent color used for the checkmarks and button β€” approximated as a medium blue.

function PricingCard({ planName, price, features, ctaText, onSelect }) {
return (
<div className="rounded-2xl shadow-md p-6 max-w-sm bg-white">
<h3 className="text-lg font-bold text-gray-900">{planName}</h3>
<p className="text-3xl font-extrabold mt-2">{price}</p>
<ul className="mt-4 space-y-2">
{features.map((feature) => (
<li key={feature} className="flex items-center gap-2 text-sm text-gray-700">
<span className="text-blue-600">&#10003;</span>
{feature}
</li>
))}
</ul>
<button
onClick={onSelect}
className="mt-6 w-full rounded-lg bg-blue-600 py-2 text-white font-semibold"
>
{ctaText}
</button>
</div>
);
}

Note: verify the exact accent blue against the original design once rendered β€” it was approximated from a compressed screenshot.

When to use it

  • Turning a Figma export or design mockup into a first-pass React component instead of building it from scratch
  • Recreating a UI pattern you found on another site as a reusable component
  • Prototyping quickly during a design review when you need working code to test interactions, not just a static image
  • Handing a junior developer a starting point that already matches the intended design closely

Best practices

  • Attach the highest-resolution version of the screenshot or mockup you have, since small text and subtle spacing get lost in compressed images
  • Specify your stack up front (React version, styling approach like Tailwind or CSS Modules, and any component library already in use) so the output matches your codebase conventions
  • Ask the model to flag anything it had to guess (like an exact color value it couldn't read clearly) instead of presenting guesses as certainties
  • Review the generated component against the original design side by side rather than assuming a visual match on the first pass

Common mistakes

  • Uploading a low-resolution or cropped screenshot and expecting exact spacing and color values to be inferred correctly
  • Not specifying the tech stack, resulting in code that doesn't match your project's styling approach or component patterns
  • Asking for the whole page at once instead of breaking a complex design into smaller components generated one at a time
  • Treating the first output as final without checking it against real browser rendering, since a description-based build can miss responsive behavior

Related Cuelara Tools

This prompt only goes as far as the image you feed it. One Cuelara tool pairs especially well with it:

  • Site to Prompt β€” measures a real rendered webpage (not just a screenshot) and turns its actual layout, spacing, typography, and colors into a ready-to-use prompt, which removes most of the guesswork this template otherwise has to flag.

FAQs

Can ChatGPT or Claude turn a screenshot into React code?

Yes, vision-capable versions of both can read an attached image and generate matching component code, though accuracy depends on image resolution and how clearly the prompt specifies the tech stack and constraints.

Why is my AI-generated component's spacing off from the design?

This usually comes from a low-resolution or compressed screenshot where exact pixel spacing isn't clearly visible, or from not asking the model to flag uncertain measurements before writing code.

How do I get consistent styling when converting multiple screens to React components?

Specify the same styling approach and tech stack in every prompt, and consider building a shared component/design reference the model can be pointed to, so spacing and color choices stay consistent across components.

Should I convert a whole page or one component at a time?

One component or section at a time generally works better β€” a full-page request makes it harder for the model to get every section's details right and harder for you to review the output.

Does this approach work for design tools other than Figma?

Yes, it works with any image the model can read, including screenshots of live websites, hand-drawn wireframes, or exports from Sketch or Adobe XD, since the prompt works from the visual description rather than any specific file format.

Found this prompt useful? Share it.

Share