figma-to-code
Figma-to-code workflow: extracting design tokens from Figma Variables, syncing tokens with Style Dictionary, reading Figma files via API, handoff conventions, and maintaining parity between design and implementation. For teams with a designer.
Best use case
figma-to-code is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Figma-to-code workflow: extracting design tokens from Figma Variables, syncing tokens with Style Dictionary, reading Figma files via API, handoff conventions, and maintaining parity between design and implementation. For teams with a designer.
Teams using figma-to-code should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/figma-to-code/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How figma-to-code Compares
| Feature / Agent | figma-to-code | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Figma-to-code workflow: extracting design tokens from Figma Variables, syncing tokens with Style Dictionary, reading Figma files via API, handoff conventions, and maintaining parity between design and implementation. For teams with a designer.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Figma-to-Code Skill
## When to Activate
- A designer works in Figma and you need design tokens in code
- Design and code are drifting out of sync (different colors, spacing)
- Setting up an automated token sync pipeline
- Translating a Figma component into React for the first time
- Establishing handoff conventions between design and engineering
---
## The Core Problem
Without a sync pipeline:
- Designer changes `--blue-600` to `#2563eb` in Figma
- Developer doesn't know
- Production stays at `#3b82f6`
- Design and code drift apart over weeks
**Solution:** Figma Variables → export → Style Dictionary → CSS/TS tokens → commit to repo.
---
## Step 1: Figma Variables Setup (designer's job)
Figma Variables map directly to CSS Custom Properties. Establish this convention with your designer:
```
Figma Variable collection structure:
Primitives (raw values):
colors/blue/500 = #3b82f6
colors/blue/600 = #2563eb
spacing/4 = 16
radius/md = 6
Semantic (light mode):
color/brand = {colors/blue/600}
color/surface = #ffffff
color/text/primary = #111827
Semantic (dark mode): ← same names, different values via mode
color/brand = {colors/blue/500}
color/surface = #0f172a
color/text/primary = #f8fafc
```
This maps 1:1 to your `tokens/colors.css` from the design-system skill.
---
## Step 2: Export Tokens from Figma
### Option A: Figma Tokens Plugin (free)
1. Install "Tokens Studio for Figma" plugin
2. Connect to GitHub repository
3. Auto-syncs Figma Variables to `tokens/` JSON files on push
```json
// tokens/semantic.json (auto-generated by plugin)
{
"color": {
"brand": { "value": "{colors.blue.600}", "type": "color" },
"surface": { "value": "#ffffff", "type": "color" },
"text": {
"primary": { "value": "#111827", "type": "color" },
"secondary": { "value": "#6b7280", "type": "color" }
}
},
"spacing": {
"4": { "value": "16", "type": "spacing" },
"6": { "value": "24", "type": "spacing" }
}
}
```
### Option B: Figma Variables REST API (programmatic)
```typescript
// scripts/sync-tokens.ts
const FIGMA_FILE_ID = process.env.FIGMA_FILE_ID!;
const FIGMA_TOKEN = process.env.FIGMA_ACCESS_TOKEN!;
async function fetchFigmaVariables() {
const response = await fetch(
`https://api.figma.com/v1/files/${FIGMA_FILE_ID}/variables/local`,
{ headers: { 'X-Figma-Token': FIGMA_TOKEN } }
);
return response.json();
}
// Run: npx ts-node scripts/sync-tokens.ts
// Commit the output to version control
```
---
## Step 3: Style Dictionary (tokens → platform outputs)
Style Dictionary transforms raw JSON tokens into CSS, TypeScript, iOS, Android — one source, many targets.
```bash
npm install --save-dev style-dictionary
```
```javascript
// style-dictionary.config.js
import StyleDictionary from 'style-dictionary';
const sd = new StyleDictionary({
source: ['tokens/**/*.json'],
platforms: {
css: {
transformGroup: 'css',
prefix: 'ds',
buildPath: 'src/styles/generated/',
files: [
{
destination: 'tokens.css',
format: 'css/variables',
options: { outputReferences: true },
},
],
},
typescript: {
transformGroup: 'js',
buildPath: 'src/styles/generated/',
files: [
{
destination: 'tokens.ts',
format: 'javascript/es6',
},
],
},
},
});
sd.buildAllPlatforms();
```
```bash
# Package.json script
"tokens:build": "node style-dictionary.config.js",
"tokens:sync": "npx ts-node scripts/sync-tokens.ts && npm run tokens:build"
```
**Output** (`src/styles/generated/tokens.css`):
```css
:root {
--ds-color-brand: #2563eb;
--ds-color-surface: #ffffff;
--ds-color-text-primary: #111827;
--ds-spacing-4: 16px;
}
```
---
## Step 4: Reading a Figma Component for Implementation
When implementing a component from Figma, extract in this order:
### 1. Structure first (HTML semantics)
```
Figma layer: "Card / Product"
├─ Image (rectangle with image fill)
├─ Content
│ ├─ Title (text)
│ ├─ Description (text)
│ └─ Price (text)
└─ Actions
└─ Button / Add to cart
→ Semantic HTML:
<article>
<img />
<div> (content)
<h3>
<p>
<p> (price)
</div>
<footer>
<button>
</footer>
</article>
```
### 2. Spacing (always check all 4 sides)
```
Figma: inspect → spacing
Padding: 16px all sides = p-4
Gap between elements: 12px = gap-3
```
### 3. Typography (always check weight + size + line-height)
```
Title: Inter 16px / SemiBold / line-height 24px
= text-base font-semibold leading-normal
Price: Inter 14px / Bold / line-height 20px
= text-sm font-bold
```
### 4. Colors → token names (never use hex directly)
```
Background: #ffffff → bg-surface
Border: #e5e7eb → border-border
Title: #111827 → text-text-primary
Price: #2563eb → text-text-brand
```
### 5. Interactive states (hover, focus, disabled)
```
Always ask: "What does this look like on hover / focus / disabled?"
If not in Figma, establish the convention yourself using the design system.
```
---
## Handoff Conventions
Establish these with your designer once, document in your team wiki:
| Convention | Agreement |
|---|---|
| Spacing | Designer uses 8px grid; developer uses `--space-*` tokens |
| Colors | Designer uses Variables; developer uses `--color-*` semantic tokens |
| Typography | Designer uses text styles; developer uses `--text-*` tokens |
| Breakpoints | Agreed breakpoint names: `sm/md/lg/xl` |
| States | Designer provides: default, hover, focus, disabled, error |
| Icons | Agreed icon library (Lucide, Heroicons, Phosphor) |
| Images | Designer specifies: aspect ratio, min/max size, object-fit |
| Redline units | Always px in Figma; developer converts to rem |
---
## CI Token Sync Pipeline
```yaml
# .github/workflows/sync-tokens.yml
name: Sync Design Tokens
on:
schedule:
- cron: '0 9 * * 1' # Every Monday morning
workflow_dispatch: # Also runnable manually
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 24 }
- run: npm ci
- name: Fetch tokens from Figma
env:
FIGMA_ACCESS_TOKEN: ${{ secrets.FIGMA_ACCESS_TOKEN }}
FIGMA_FILE_ID: ${{ secrets.FIGMA_FILE_ID }}
run: npm run tokens:sync
- name: Create PR if tokens changed
uses: peter-evans/create-pull-request@v6
with:
title: 'chore: sync design tokens from Figma'
body: 'Auto-generated: design tokens updated from Figma Variables.'
branch: chore/sync-tokens
commit-message: 'chore: sync design tokens from Figma'
```
---
## Red Flags (Design-Code Drift)
- Hardcoded hex values in components (`text-[#2563eb]`) — use tokens
- "Just eyeball it" spacing — use the scale
- Components in code that don't exist in Figma — add them to Figma
- Figma components that aren't implemented — note as tech debt
- Token names in code that differ from Figma variable names — unify them
---
## Checklist
- [ ] Figma Variables organized: Primitives + Semantic (light + dark modes)
- [ ] Token export automated (plugin or API + script)
- [ ] Style Dictionary converts tokens to CSS Custom Properties
- [ ] Generated token files committed to repo (not gitignored)
- [ ] CI workflow syncs tokens weekly or on designer push
- [ ] Handoff conventions documented and agreed with designer
- [ ] Component implementation checks all 5 layers: structure, spacing, typography, color, states
- [ ] No hardcoded hex/px values — always token references in componentsRelated Skills
zero-trust-patterns
Zero-Trust security patterns — mTLS between microservices (Istio/SPIFFE), SPIRE workload identity, OPA/Envoy authorization, NetworkPolicy default-deny-all, short-lived credentials, service mesh security, and Kubernetes RBAC hardening.
wireframing
Wireframing and prototyping workflow: fidelity levels (lo-fi sketch → mid-fi wireframe → hi-fi prototype), tool selection (Figma, Excalidraw, Balsamiq), user flow diagrams, wireframe annotation standards, information architecture (IA) mapping, and the handoff from wireframe to visual design. For developers who need to communicate UI structure before writing code.
webrtc-patterns
WebRTC patterns — peer connection setup, ICE/STUN/TURN configuration, signaling server design, SFU vs mesh topology, screen sharing, media track management, and reconnect/ICE restart handling.
webhook-patterns
Webhook patterns for receiving, verifying (HMAC), and idempotently processing third-party events. Covers Stripe, GitHub, and generic webhook patterns, delivery guarantees, retry handling, and testing.
web-performance
Web performance optimization: Core Web Vitals (LCP, CLS, INP), Lighthouse CI with budget configuration, bundle analysis (webpack-bundle-analyzer, vite-bundle-visualizer), hydration performance, network waterfall reading, image optimization (WebP/AVIF, srcset), and font performance.
wasm-performance
WebAssembly performance: wasm-opt binary optimization, size reduction (panic=abort, LTO, strip), profiling WASM in Chrome DevTools, memory management (linear memory, avoiding GC pressure), SIMD, and multi-threading with SharedArrayBuffer.
wasm-patterns
WebAssembly patterns: wasm-pack, wasm-bindgen (JS↔Wasm interop), WASI, Component Model, wasm-opt, Rust-to-WASM compilation, JS integration (web workers, streaming instantiation), and production deployment (CDN, Content-Type headers).
visual-testing
Visual Regression Testing: tool comparison (Chromatic/Percy/Playwright screenshots/BackstopJS), pixel-diff vs AI-based comparison, baseline management, flakiness strategies (masks, tolerances, waitForLoadState), CI integration with GitHub Actions, and Storybook integration.
visual-identity
Brand identity development: color palette construction (primary/secondary/semantic/neutral), logo concept brief writing, typeface pairings, brand voice definition, mood board direction, and Brand Guidelines document structure. Use when establishing or evolving a visual brand — not for implementing existing tokens.
ux-micro-patterns
UX micro-patterns for every product state: Empty States, Loading States (skeleton screens, spinners, optimistic UI), Error States, Success States, Confirmation Dialogs, Onboarding Flows, and Progressive Disclosure. These patterns apply to every feature — done wrong, they're the biggest source of user confusion.
typography-design
Typography as a creative discipline: typeface selection criteria, type pairing (serif + sans, display + body), modular scale systems, line-height and tracking ratios, hierarchy construction, and web/mobile rendering considerations. The decisions behind design tokens, not the tokens themselves.
typescript-testing
TypeScript testing patterns: Vitest for unit/integration, Playwright for E2E, MSW for API mocking, Testing Library for React components. Core TDD methodology for TypeScript/JavaScript projects.