Skip to main content

How to get pixel-perfect UI from Claude Code and Cursor

Stop describing the design and give the agent measurements. Extract the exact colours, font sizes, borders, radii and layout from the screenshot, have Claude Code or Cursor build from those numbers at the reference size, then screenshot the result and compare it with the reference until the differences are gone.

Why agents get UI almost right

Vibe-coded UI fails in a predictable way. The layout is roughly right, but every value is slightly off: the card background is bg-zinc-900 instead of #18181B, the label is text-sm instead of 13px, the radius is rounded-lg instead of 6px. Three causes:

  • Downscaled vision. Models see large screenshots at reduced resolution, so 1px borders and subtle greys blur together.
  • Defaults win. When unsure, models choose the most common value they have seen — usually a framework default.
  • No feedback. The agent rarely checks its output against the reference, so small errors never get corrected.

The fix: measure → build → verify

  1. Measure the reference. Extract exact colours, font sizes, weights, borders, radii and layout from the design screenshot instead of describing it.
  2. Give the agent numbers. Paste the measured prompt (or call the MCP tools) so the agent builds from values, not from a downscaled image.
  3. Build at the reference size. Implement at the screenshot’s dimensions first, then make it responsive.
  4. Verify against the reference. Screenshot the build at the same viewport and compare it with the reference; fix the reported differences and repeat.

Step 1 in practice

Drop the screenshot into the Datum converter. It measures every surface (fill, border, radius) and every text line (size, weight, colour) and nests them into a layout tree:

▣ Card [32, 84, 363, 132] — bg #18181B, border 1px #27272A, radius 6px
  T "Total ARR" — 13px regular #A1A1AA
  T "$142,850" — 28px bold #FAFAFA
  T "+14.2% from last month" — 13px regular #22C55E

On our benchmark that measurement was exact for surface colours, within ΔE 3 for 98.6% of text colours and within ±1px for 93.1% of font sizes.

Step 4 in practice: let the agent check itself

With the Datum MCP server, Claude Code or Cursor can screenshot your running app on localhost and compare it with the reference, then fix what is reported. Without MCP, use the verify page to compare a screenshot of your build and copy the correction prompt.

Prompt you can reuse

Build this screen from design-references/dashboard.png using the Datum tools.
Use the measured values exactly; map them to existing theme tokens only when identical.
Implement at the reference size first, then verify against the reference and fix differences.

Related

Questions

Why does Claude Code’s UI not match my design?
Because it is reproducing an image it sees at reduced resolution and filling gaps with common defaults. It rounds colours to familiar values, picks standard Tailwind sizes, and guesses spacing. Giving it measured values removes the guessing.
Is pasting a screenshot into Cursor enough?
It gets you close, rarely exact. Large screenshots are downscaled before the model sees them, so thin borders, 1px differences and subtle greys are lost. A measured spec keeps them.
Do I need Figma for pixel-perfect results?
No. A Figma file gives exact values directly, but when all you have is a screenshot, measuring the pixels recovers most of the same values: colours, font sizes, weights, borders, radii and bounds.