Tutorial 4 of 4
Design to Code
The design skills a frontend developer needs: how to read a Figma file, turn it into tokens and components, and build a small reusable component kit. Components use Tailwind and work the same in React and Next.
Read a Figma file like a developer
Switch to Dev Mode (the </> toggle, or Shift + D). Click any layer and the Inspect panel shows its size, spacing, colors and text style. Hold Alt and hover another layer to see the distance between them.
| Figma term | What it means for you |
|---|---|
| Frame | A container: a div, a section or a whole screen |
| Auto layout | Flexbox. Direction, gap, padding and alignment map one to one |
| Component | A reusable piece: one component file in your code |
| Variant / property | A prop: size, variant, disabled |
| Instance | A usage of the component: <Button /> |
| Variables / styles | Design tokens: named colors, spacing, radius, text styles |
| Constraints, Fill, Hug | Responsive behavior: Fill = flex: 1 or width: 100%, Hug = size of content |
Habit: before writing code, list the components and tokens the screen uses. Build those first, then the screen is mostly assembly.
Design tokens
A token is a named design decision. You write bg-primary, not #0b7285, so a rebrand or dark mode is a change in one file. Copy the names from Figma's Variables panel.
Without Tailwind, the same idea is plain CSS variables on :root and var(--color-primary) in your styles.
Spacing and layout
Good layouts use a small set of spacing values, almost always multiples of 4: 4, 8, 12, 16, 24, 32, 48. If Figma shows 15 or 17, it is probably meant to be 16. Tailwind's scale is the same grid: p-4 is 16px, gap-6 is 24px.
| Auto layout setting | CSS | Tailwind |
|---|---|---|
| Horizontal | display: flex | flex |
| Vertical | flex-direction: column | flex flex-col |
| Gap 16 | gap: 16px | gap-4 |
| Padding 24 | padding: 24px | p-6 |
| Space between | justify-content: space-between | justify-between |
| Wrap | flex-wrap: wrap | flex-wrap |
- Use
gapon the parent for space between siblings. Avoid margins on children. - Related things sit close together, unrelated things get more space. Spacing is how a page shows grouping.
- Use flex for a row or a column, grid for rows and columns together (card grids, page shells).
Typography
Use a fixed scale of sizes, not arbitrary numbers. Five or six steps cover a whole app.
| Role | Size / line height | Tailwind |
|---|---|---|
| Page title | 30 / 36, bold | text-3xl font-bold |
| Section title | 20 / 28, semibold | text-xl font-semibold |
| Body | 16 / 24 | text-base |
| Secondary text | 14 / 20, muted color | text-sm text-muted |
| Label, caption | 12 / 16, medium | text-xs font-medium |
- Hierarchy comes from size, weight and color together. Do not use more than two font families.
- Keep paragraphs around 60 to 70 characters wide:
max-w-prose. - Body text below 14px is hard to read. On phones keep inputs at 16px so iOS does not zoom.
Color and contrast
- One primary color for the main action on a screen. If everything is colored, nothing stands out.
- Neutrals do most of the work: background, surface, border, text, muted text.
- Semantic colors carry meaning: success, warning, danger. Never rely on color alone, add an icon or text.
- Contrast: text needs a ratio of at least 4.5:1 against its background (3:1 for large text). Check it in Chrome DevTools by clicking the color swatch.
Dark mode is the same tokens with different values, which is why components must never contain raw hex codes.
Responsive design
Write the phone layout first, then add changes at wider breakpoints. In Tailwind an unprefixed class applies everywhere and md: applies from 768px up.
| Prefix | From | Typical device |
|---|---|---|
| none | 0 | Phone |
sm: | 640px | Large phone |
md: | 768px | Tablet |
lg: | 1024px | Laptop |
xl: | 1280px | Desktop |
Ask the designer: if Figma only has a desktop frame, ask what stacks, what hides and what scrolls on a phone. Do not guess silently.
Design every state
A mockup usually shows the happy path. Real components have more states, and missing ones are the most common gap between design and code.
| For controls | For data views |
|---|---|
| Default | Loading (skeleton or spinner) |
| Hover | Empty (no data yet, with a next step) |
| Focus (keyboard) | Error (what failed, how to retry) |
| Active / pressed | Partial (some rows, long text, missing image) |
| Disabled | Success (confirmation after an action) |
Design a component's API
A good component mirrors the Figma component: each Figma property becomes one prop with the same options. Rules that keep components reusable:
- Variants are a fixed list (
"primary" | "secondary"), not free-form class strings. - Extend the native element's props, so
onClick,type,disabledandaria-*work for free. - Content goes in
children. Layout around the component (margins, position) belongs to the parent. - Accept
classNameas an escape hatch for one-off adjustments.
A starter component kit
These few components cover most screens. Keep them in components/ui/.
TextField: label, input and error together
Card: a surface with optional title
Badge: status at a glance
Modal: built on the native dialog element
The browser's <dialog> gives you focus trapping, Escape to close and a backdrop without a library.
Skeleton and EmptyState: the forgotten states
Accessibility basics
Most of accessibility is using the right HTML element. These six habits cover the majority of issues:
- Something that does an action is a
<button>. Something that goes to a URL is an<a>. Never a clickable<div>. - Every input has a
<label>linked byhtmlFor. A placeholder is not a label. - Every image has
alt. Usealt=""for purely decorative ones. - Never remove the focus outline without replacing it. Test the page using only Tab, Enter and Escape.
- Icon-only buttons need a name:
<button aria-label="Close">. - One
<h1>per page, then headings in order. Screen readers navigate by them.
Click targets should be at least 40 by 40 pixels, larger on touch screens.
Check it
- Chrome DevTools, Lighthouse tab, Accessibility audit: catches missing labels, alt text and low contrast.
- Unplug the mouse and complete the main task with the keyboard.
- Add the lint plugin so mistakes fail early:
npm install -D eslint-plugin-jsx-a11y(already included in the Next ESLint config).
Icons and assets
- Icons: use one icon library, or export from Figma as SVG. Set
fill="currentColor"so the icon takes the text color. - Photos and illustrations: export at 2x as WebP. In Next use
next/image. - Logos: SVG, never PNG.
An icon exported from Figma as a component
Paste the exported SVG into a component, replace the fixed color with currentColor, and pass props through so size and color come from the parent.
Note the JSX spelling: strokeWidth, not stroke-width. Keep the viewBox, it is what lets the icon scale.
Figma to code with an AI agent
The Figma MCP server lets a coding agent read the selected frame: its layout, variables, components and a screenshot. Connect once:
In Figma, right click a frame and choose Copy link to selection. Then give the agent a specific prompt:
What makes the output good: a tidy Figma file. Auto layout everywhere, named layers, real components and variables. A frame made of loose rectangles produces absolutely positioned junk.
Always review the result against the design at phone and desktop widths. Treat generated code as a first draft.
Code Connect: link Figma components to yours
Code Connect tells Figma which code component matches each Figma component. Dev Mode then shows your real import and props, and AI agents reuse your component and do not invent a new one.
The left side of each mapping is the property name in Figma, the right side is your prop value. This is why matching names between design and code pays off.
Do not build everything yourself
Dropdowns, date pickers, comboboxes and tooltips are hard to get right. Use a library for those and write only the simple pieces by hand.
shadcn/ui
Copies accessible, Tailwind-styled components into your repo, so you own and can edit the code.
The files land in components/ui/. Import and use them like your own:
To match your Figma file, edit the color variables shadcn adds to globals.css. Every component picks them up.
Storybook
A workshop that shows each component alone, in every variant and state. Useful for reviewing against Figma with a designer.
A story is one named state of a component. Write one per variant the Figma component has.
When to use what
| Need | Reach for |
|---|---|
| Button, card, badge, input | Write it yourself (the kit above) |
| Dropdown, dialog, tabs, tooltip, combobox | shadcn/ui |
| Date picker, data table, charts | A dedicated library (react-day-picker, TanStack Table, Recharts) |
| Form state and validation | React Hook Form with Zod |
| Reviewing components with a designer | Storybook |
Handoff checklist
Run through this before calling a screen done.
- Colors, spacing and radius come from tokens, with no raw values in components.
- Spacing matches Figma at the three widths: phone, tablet, desktop.
- Hover, focus, disabled, loading, empty and error states exist.
- Long text, missing images and zero items do not break the layout.
- The page works with the keyboard only, and focus is always visible.
- Text contrast passes 4.5:1 in light and dark mode.
- Repeated UI was extracted into
components/ui, not copied. - You compared the browser and the Figma frame side by side at 100% zoom.