Screenshot-to-Component: Building a Token-Driven Card with Chips
System DesignModel answerLast updated
Turn a static card-and-chip screenshot into a tokenized, accessible, responsive component and explain how you'd verify pixel fidelity.
You are given a single static screenshot of a card: rounded container, a heading, a short body line, and a row of small pill-shaped chips, one of which appears highlighted. Your job is not to trace the image — it is to reverse-engineer the design behind it and rebuild it as a real component.
Deliver a short working implementation (any mainstream framework or plain HTML/CSS/JS is fine) plus a verbal walkthrough covering:
- Token extraction — how you read spacing, radius, color, type scale, and shadow off the screenshot and turn them into named variables rather than magic numbers.
- Structure — semantic markup and a data-driven render for the chips (the chip set is a prop/array, not copy-pasted markup).
- Behavior and states — hover, focus-visible, active/selected, disabled; whether chips are static labels or interactive controls.
- Responsive and overflow rules — what happens at narrow widths, with long labels, and with many chips.
- Verification — how you convince yourself and a reviewer that the result matches the reference, and which edge cases you'd test.
Assume the screenshot is authoritative for appearance but silent about interaction. State your assumptions explicitly, and ask about anything that changes the implementation.
Hints
Hint 1
Start by measuring, not coding: overlay a grid on the screenshot and pull out the 4/8px spacing rhythm, the corner radius, and the font sizes before you write a single rule.
Hint 2
Decide early whether chips are presentational or actionable — that single answer flips your markup between a plain list and a group of toggle buttons or filter controls.
Hint 3
Fidelity is a test, not a vibe: pin the reference viewport and device pixel ratio, then diff screenshots in CI at a fixed tolerance.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing the answer
The screenshot tells me what it looks like, not how it behaves. So I split the work: first I convert pixels into a small design-token layer, then I build a data-driven component on top of those tokens, then I write down what the screenshot can't answer and either ask or assume out loud.
Step 1 — Extract tokens before writing markup
I open the screenshot at 100% and note the viewport width and device pixel ratio, because everything downstream depends on those two numbers. Then I measure with an overlay grid rather than eyeballing:
- Spacing rhythm. Almost every gap (card padding, gap between chips, gap between heading and body) snaps to multiples of 4 or 8. I record the base unit (usually 4px) and express padding as
space-4,space-6, etc. - Radius. One or two values only — say 12px for the card, 999px (full pill) for chips. If two radii differ by 2px I treat it as one token.
- Type scale. Estimate font sizes from cap height and line height, then round to a sensible scale (14/16/20). Line height is a ratio, typically 1.4–1.6.
- Color. Sample fills and text with an eyedropper, then map each to a semantic name:
surface,surface-raised,text-primary,text-muted,accent,accent-soft,border-subtle. I check text-on-background contrast (WCAG AA wants 4.5:1 for body, 3:1 for large text) while sampling, since a screenshot often reveals a failing pair. - Elevation. A card shadow is usually a two-layer shadow; I copy the blur and offset, not the exact color, and express it as a token.
The payoff: every value in the CSS is a variable, so a designer's "make the chips 2px taller" is a one-line change.
Step 2 — Structure and data-driven rendering
<article class="card">
<h2 class="card__title">{title}</h2>
<p class="card__body">{description}</p>
<ul class="chip-list" role="list">
{chips.map(c => <li><Chip {...c} /></li>)}
</ul>
</article>
Chips come from an array prop ([{ id, label, selected }]), never from repeated markup. The card is an <article> because it's a self-contained unit; the heading gives it an accessible name. The list is a real <ul> so screen readers announce "list, N items" — with role="list" restored because list-style: none strips semantics in Safari.
Step 3 — Interaction and states
The screenshot can't tell me whether chips filter, toggle, or just label. I ask. If they're informational, they're plain <li> text with muted styling — no tab stops, no cursor change. If they're toggle filters, the highlighted chip becomes aria-pressed (or a role="radio" group if mutually exclusive) on a real <button>, inside a labelled <fieldset>/role="group" with an accessible name like "Filters". If they're removable, I add a delete button with aria-label="Remove {label}" and make sure the delete target is at least 24×24px.
Regardless, focus must be visible: :focus-visible with a 2px outline offset from the edge, never outline: none without a replacement. Hover and active states get their own tokens so the design system stays coherent. I mention prefers-reduced-motion if any transition exists — a 120ms color fade is fine, but it should be suppressible.
Step 4 — Responsive and overflow
- Narrow widths. Chips wrap (
flex-wrap: wrap) rather than shrink below their text; the card goes full width under ~480px with padding reduced one step on the spacing scale. - Long labels. Chip text truncates with
text-overflow: ellipsisandmax-widthonly if the design demands single-line chips; otherwise let them wrap and grow. Long card titles clamp to two lines with-webkit-line-clamp. - Many chips. Either the row scrolls horizontally (with a keyboard-reachable scroller, not a mouse-only one) or an overflow "+3" affordance appears. I flag this as a product decision.
- Unicode/CJK and zoom. Test at 200% browser zoom and with long German compound words; fixed heights are the usual culprit when this breaks.
Step 5 — Verification
Fidelity gets measured, not argued. I pin the reference viewport (e.g. 375×812 at DPR 2), render the component in isolation, and diff against the screenshot in a visual-regression tool with a small pixel tolerance (0.1–0.5%) to absorb anti-aliasing. I also compare computed styles for the key tokens, and I keep the reference image in the repo next to a snapshot test so future changes can't silently drift.
Edge-case checklist: empty chip array (list disappears without leaving an orphaned gap), one very long label, 20 chips, RTL direction, dark mode if the token layer supports it, keyboard-only tab order, and a screen-reader pass to confirm the list is announced correctly.
Common mistakes
Hard-coding absolute pixel positions or dropping the screenshot in as a background image; ignoring the reference DPR so everything looks 2× off; skipping the interactive-vs-static question and shipping a non-functional button; outline: none; chips that overflow their container at 320px; and calling it done because it "looks close" with no screenshot diff.