Back to cookbook

AI Prompt to Turn a Design Screenshot into a React Component

27 views Published

Make this prompt yours

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

Make this prompt yours

prompt-template
285 tokens
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

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
191 tokens
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

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

More in React Prompt Recipes

React Prompt Recipes

AI Prompt to Build a React Kanban Board With Drag-and-Drop

This prompt gives ChatGPT, Claude, or Gemini a complete specification for building a React Kanban board with drag and drop column reordering…

You are a senior React developer specializing in accessible, production-ready UI components.

Context:
- Framework: [REACT VERSION, e.g. React 18 with TypeScript]
- Drag-and-drop library: [LIBRARY NAME, e.g. @dnd-kit/core]
- Styling approach: [e.g. Tailwind CSS, CSS Modules, styled-components]
- Columns or workflow stages: [LIST OF COLUMN NAMES, e.g. Backlog, In Progress, Review, Done]
- State source: [e.g. local state, Zustand store, REST API endpoint]

Build a Kanban board component with the following requirements:
1. Render one column per workflow stage listed above, each showing its card count
2. Support dragging cards between columns and reordering cards within a column
3. Support keyboard-based reordering, not mouse-only interaction, for accessibility
4. Identify cards by a stable [ID FIELD NAME] field, never by array index
5. Call a [CALLBACK NAME] function on every successful move, passing the card id, source column, destination column, and new index
6. Show an optimistic UI update immediately, then roll back if [CALLBACK NAME] rejects
7. Handle empty columns and drops outside any valid column gracefully

Output format:
- The main board component
- Column and Card subcomponents
- Any custom hooks used for drag state
- A short usage example showing how to wire [CALLBACK NAME] to a real API call
- Brief notes on any library-specific setup required, such as providers, context, or CSS imports

Make this prompt yours

React Prompt Recipes

AI Prompt for an Accessible React Autocomplete Combobox

This prompt is for developers asking Claude , ChatGPT , or Gemini to generate a React autocomplete combobox component, the input plus dropdo…

Generate a React component with the following specification.

ROLE
- You are a frontend engineer who writes accessible, production-ready React components.

COMPONENT
- A searchable autocomplete combobox named [COMPONENT NAME].
- Props: options ([OPTION SHAPE, e.g. array of {id, label}]), value, onChange, placeholder.
- Controlled component: value and onChange are provided by the parent; do not manage selected value as internal-only state.

ACCESSIBILITY REQUIREMENTS
- Use the ARIA 1.2 combobox pattern: role="combobox" on the input, role="listbox" on the options container, role="option" on each item, and aria-activedescendant to track the highlighted option.
- Support keyboard interaction: ArrowDown/ArrowUp to move highlight, Enter to select the highlighted option, Escape to close the list, Home/End to jump to first/last option.
- Announce the number of matching results to screen readers when the list updates.

BEHAVIOR
- Filter options client-side, debounced by [DEBOUNCE MS, e.g. 150]ms.
- Close the dropdown on click outside or on Escape.
- If no options match, display [EMPTY STATE MESSAGE] inside the listbox instead of hiding it.

OUTPUT FORMAT
- A single functional component using hooks, written in [TYPESCRIPT OR JAVASCRIPT], with inline comments marking each accessibility feature.

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Command Palette (Cmd+K) Component

This AI prompt generates a complete React command palette component, the kind of Cmd+K (or Ctrl+K) search and action overlay popularized by…

ROLE: You are a senior frontend engineer who writes accessible, reusable React components with TypeScript.

TASK: Build a command palette (Cmd+K / Ctrl+K) component for a React application with the following behavior:
1. A global keyboard shortcut ([SHORTCUT, E.G. CMD+K]) opens the palette from anywhere in the app.
2. The palette renders as a centered modal overlay with a search input focused automatically on open.
3. Below the input, show a filtered, scrollable list of commands based on a prop-driven array of {id, label, icon, action, group} items.
4. Support fuzzy or substring matching on the label as the user types, updating the list in real time.
5. Support arrow-up/arrow-down to move the active selection and Enter to run the selected command's action and close the palette.
6. Escape closes the palette and returns focus to whatever element triggered it.
7. Group commands by their 'group' field with a small header label per group in the results list.

CONSTRAINTS:
- Use React hooks only, no class components.
- Trap focus inside the palette while it is open.
- Use ARIA roles appropriate for a combobox/listbox pattern.
- Style with [STYLING APPROACH, E.G. TAILWIND CSS / CSS MODULES].

OUTPUT FORMAT: A single CommandPalette.tsx component file plus a short usage example showing how to pass the command list and mount the component, with brief inline comments explaining the keyboard and focus logic.

APP CONTEXT: [BRIEF DESCRIPTION OF THE APP AND EXAMPLE COMMANDS, E.G. 'PROJECT MANAGEMENT TOOL WITH COMMANDS LIKE NEW TASK, GO TO SETTINGS, INVITE TEAMMATE']

Make this prompt yours