Extracts Figma variables and transforms them into code-ready design tokens...
This skill extracts design tokens (variables and styles) from Figma and transforms them into production-ready code formats. It bridges the gap between Figma's variable system and your codebase's token architecture.
Related documentation:
https://figma.com/design/:fileKey/:fileName?node-id=1-2figma-desktop MCP: User can select a node directly in the Figma desktop appFollow these steps in order. Do not skip steps.
Ask the user or infer from context:
| Scope | When to Use | Node Selection |
|---|---|---|
| Component-level | Tokens for a specific component | Select the component node |
| Page-level | All tokens used on a page | Select the page or top frame |
| Full system | Complete design token set | Select a frame that uses all tokens |
Extract from the Figma URL:
/design/node-id parameter (convert 1-2 to 1:2)Example:
URL: https://figma.com/design/kL9xQn2VwM8pYrTb4ZcHjF/DesignSystem?node-id=42-15
File key: kL9xQn2VwM8pYrTb4ZcHjF
Node ID: 42:15
Run get_variable_defs to extract tokens:
get_variable_defs(fileKey=":fileKey", nodeId=":nodeId")
Extracts:
Before generating output, check the codebase for existing token files:
Common locations:
src/styles/tokens.csssrc/theme/variables.csstokens/ directorytailwind.config.js or tailwind.config.tssrc/styles/theme.tsDetermine:
Transform extracted tokens to match the project's format and conventions.
:root {
/* Colors - Primitives */
--color-blue-500: #3b82f6;
--color-gray-900: #111827;
/* Colors - Semantic */
--color-background: var(--color-white);
--color-text-primary: var(--color-gray-900);
/* Spacing */
--space-1: 4px;
--space-2: 8px;
/* Typography */
--font-size-base: 16px;
--line-height-normal: 1.5;
/* Radius */
--radius-md: 8px;
}
/* Dark mode */
[data-theme="dark"] {
--color-background: var(--color-gray-900);
--color-text-primary: var(--color-white);
}
{
"color": {
"background": {
"$value": "#ffffff",
"$type": "color"
},
"text": {
"primary": {
"$value": "#111827",
"$type": "color"
}
}
},
"spacing": {
"1": { "$value": "4px", "$type": "dimension" },
"2": { "$value": "8px", "$type": "dimension" }
}
}
export const tokens = {
colors: {
background: 'var(--color-background)',
text: {
primary: 'var(--color-text-primary)',
},
},
spacing: {
1: 'var(--space-1)',
2: 'var(--space-2)',
},
} as const;
export type ColorToken = keyof typeof tokens.colors;
export type SpacingToken = keyof typeof tokens.spacing;
// tailwind.tokens.js
module.exports = {
colors: {
background: 'var(--color-background)',
foreground: 'var(--color-text-primary)',
primary: {
DEFAULT: 'var(--color-primary)',
hover: 'var(--color-primary-hover)',
},
},
spacing: {
1: 'var(--space-1)',
2: 'var(--space-2)',
},
};
Based on project structure, generate or update token files:
New project:
tokens/
āāā colors.css
āāā spacing.css
āāā typography.css
āāā index.css (imports all)
Existing project:
Provide a summary of extracted tokens:
Token Extraction Summary
========================
Source: https://figma.com/design/.../DesignSystem?node-id=42-15
Extracted:
Colors: 24 tokens (12 primitives, 12 semantic)
Spacing: 8 tokens
Typography: 10 tokens
Radius: 4 tokens
Shadows: 3 tokens
Modes detected: Light, Dark
Files generated/updated:
ā src/styles/tokens.css
ā tailwind.tokens.js
New tokens added: 8
Updated tokens: 3
Unchanged: 38
When Figma has multiple modes (Light/Dark, Brand variants):
:root { --color-bg: #ffffff; }
[data-theme="dark"] { --color-bg: #0a0a0a; }
:root { --color-bg: #ffffff; }
@media (prefers-color-scheme: dark) {
:root { --color-bg: #0a0a0a; }
}
tokens/
āāā themes/
ā āāā light.css
ā āāā dark.css
Ask the user which approach matches their project or which they prefer.
User says: "Sync tokens from this Figma file to CSS: https://figma.com/design/abc123/Tokens?node-id=1-5"
Actions:
abc123, nodeId=1:5get_variable_defs(fileKey="abc123", nodeId="1:5")tokens.css or similarsrc/styles/tokens.css with all tokensUser says: "Update our design tokens from Figma"
Actions:
get_variable_defsUser says: "Export Figma tokens for Tailwind"
Actions:
tailwind.config.js in projecttailwind.tokens.js with theme extension formatconst tokens = require('./tailwind.tokens');
module.exports = {
theme: { extend: tokens },
};
Maintain the primitive ā semantic relationship:
blue-500: #3b82f6)primary: var(--color-blue-500))Always analyze existing tokens first. Match:
color-* vs --*-color)When modes exist, document how to switch:
// Set theme mode
document.documentElement.dataset.theme = 'dark';
Check that:
Cause: The selected node doesn't use all variables in the system. Solution: Select a higher-level frame or page that references all variables.
Cause: Variables reference other variables outside the extraction scope. Solution: Extract from a scope that includes all referenced variables, or resolve to primitive values.
Cause: Figma names don't match codebase conventions. Solution: Create a mapping and transform names during extraction.