Scopes & Code Syntax
How to configure variable scopes and code syntax (CSS, Swift, Kotlin) through $extensions in SXL Studio tokens.
Why Scopes and Code Syntax matter
When tokens are exported to Figma as Variables, they are available for binding to any property by default — fill color, stroke, dimension, gap, font. In practice this is inconvenient: a designer looking for a color also sees spacing tokens and font sizes in the picker. Search becomes chaotic.
Scopes solve this by limiting where a variable appears in the Figma UI:
- Variable
color/primary→ visible only when picking fills, strokes, and effect colors - Variable
spacing/md→ visible only when adjusting gap - Variable
borderRadius/lg→ visible only in the corner radius field
Code Syntax solves a different problem — binding to code. When a developer opens a design in Dev Mode, they see ready-to-use syntax for their platform instead of an abstract variable name:
- Web:
var(--color-primary)or$color-primary - iOS:
Color.primary - Android:
@color/primary
Both mechanisms are configured through the $extensions field in a token's JSON file.
How it works in JSON
Both settings live inside the token's $extensions block:
{
"color": {
"primary": {
"$type": "color",
"$value": "#0066FF",
"$extensions": {
"figma.scopes": ["ALL_FILLS", "STROKE_COLOR"],
"figma.codeSyntax": {
"Web": "var(--color-primary)",
"Android": "ColorPrimary",
"iOS": "Color.primary"
}
}
}
}
}
Important: keys in
$extensionsare flat strings:"figma.scopes","figma.codeSyntax","figma.hide","figma.modify". This is not a nestedfigma: { scopes: ... }object.
Scopes — variable visibility
Figma variable types
Figma supports 4 variable types. The table below lists SXL Studio token types that create Variables during Export Variables:
| Figma type | SXL Studio token types | Description |
|---|---|---|
| COLOR | color | Colors |
| FLOAT | dimension, sizing, spacing, borderRadius, borderWidth, opacity, number, fontSize, lineHeight, letterSpacing, paragraphSpacing, paragraphIndent | Numeric values |
| STRING | fontFamily, fontWeight, text | String values |
| BOOLEAN | boolean | Boolean values |
fontStyle,strokeStyle,textCase,textDecoration,duration,cubicBezier,transition,template, andcompositionmay carry reference settings in JSON/UI, but they do not create standalone Figma Variables through Export Variables.
Valid Scopes by type
COLOR
| Scope | Where the variable is visible |
|---|---|
ALL_SCOPES | Everywhere colors can be applied |
ALL_FILLS | All fill types (frame, shape, text) |
FRAME_FILL | Frame fills only |
SHAPE_FILL | Shape fills only |
TEXT_FILL | Text color only |
STROKE_COLOR | Stroke color |
EFFECT_COLOR | Effect colors (shadows, glow) |
FLOAT
| Scope | Where the variable is visible |
|---|---|
ALL_SCOPES | Everywhere numbers can be applied |
TEXT_CONTENT | Text content |
CORNER_RADIUS | Corner radius |
WIDTH_HEIGHT | Width and height |
GAP | Gap between items |
STROKE_FLOAT | Stroke width |
EFFECT_FLOAT | Numeric effect parameters |
OPACITY | Opacity |
FONT_SIZE | Font size |
LINE_HEIGHT | Line height |
LETTER_SPACING | Letter spacing |
PARAGRAPH_SPACING | Paragraph spacing |
PARAGRAPH_INDENT | First-line indent |
FONT_WEIGHT | Font weight (numeric) |
STRING
| Scope | Where the variable is visible |
|---|---|
ALL_SCOPES | Everywhere strings can be applied |
TEXT_CONTENT | Text content |
FONT_FAMILY | Font family |
FONT_STYLE | Font style (italic, bold, etc.) |
FONT_VARIATIONS | Font variations (variable fonts) |
BOOLEAN
| Scope | Where the variable is visible |
|---|---|
ALL_SCOPES | Everywhere (the only available scope) |
Default Scopes per token type
When you do not specify figma.scopes explicitly, SXL Studio uses recommended values as a reference in the editor UI. Here is the full mapping:
| Token type | Default Scopes |
|---|---|
color | ALL_FILLS, STROKE_COLOR, EFFECT_COLOR |
dimension | ALL_SCOPES |
sizing | WIDTH_HEIGHT |
spacing | GAP |
borderRadius | CORNER_RADIUS |
borderWidth | STROKE_FLOAT |
opacity | OPACITY |
number | ALL_SCOPES |
fontFamily | FONT_FAMILY |
fontWeight | FONT_STYLE |
fontStyle | FONT_STYLE |
fontSize | FONT_SIZE |
lineHeight | LINE_HEIGHT |
letterSpacing | LETTER_SPACING |
paragraphSpacing | PARAGRAPH_SPACING |
paragraphIndent | PARAGRAPH_INDENT |
text | ALL_SCOPES |
boolean | ALL_SCOPES |
duration | ALL_SCOPES |
cubicBezier | ALL_SCOPES |
strokeStyle | ALL_SCOPES |
textCase | ALL_SCOPES |
textDecoration | ALL_SCOPES |
Note: this table is a reference for the plugin's editor UI. During export, if
figma.scopesis not specified in JSON, the plugin does not write scopes to the variable — Figma's default behavior is used.
Invalid scope filtering
If you specify a scope that doesn't match the variable type (e.g., CORNER_RADIUS for a color), the plugin silently discards it. Only valid scopes from your list are applied.
{
"brand-color": {
"$type": "color",
"$value": "#FF5500",
"$extensions": {
"figma.scopes": ["ALL_FILLS", "CORNER_RADIUS", "OPACITY"]
}
}
}
Result: only ALL_FILLS is applied (the others are invalid for COLOR).
Code Syntax — code bindings
Code Syntax defines how a variable appears in Figma's Dev Mode for developers on different platforms.
Format
{
"$extensions": {
"figma.codeSyntax": {
"Web": "var(--color-primary)",
"Android": "ColorPrimary",
"iOS": "Color.primary"
}
}
}
| Key | Platform | Example values |
|---|---|---|
Web | CSS / SCSS / Less | var(--color-primary), $color-primary, @color-primary |
Android | Kotlin / Android | ColorPrimary, @color/primary, R.color.primary |
iOS | Swift / SwiftUI | Color.primary, .primary, UIColor.primary |
All three keys are optional. Specify only the platforms relevant to your team.
Auto-generation templates
Instead of writing a name manually for every token, you can use templates. The plugin automatically generates the value from the token path:
| Template | Result for color.brand.primary |
|---|---|
{var(--css-variable)} | var(--color-brand-primary) |
{$sass-variable} | $color-brand-primary |
{@less-variable} | @color-brand-primary |
{UpperCamelCase} | ColorBrandPrimary |
{lowerCamelCase} | colorBrandPrimary |
{UPPER_SNAKE_CASE} | COLOR_BRAND_PRIMARY |
{lower_snake_case} | color_brand_primary |
Template usage example:
{
"color": {
"primary": {
"$type": "color",
"$value": "#0066FF",
"$extensions": {
"figma.codeSyntax": {
"Web": "{var(--css-variable)}",
"Android": "{UpperCamelCase}",
"iOS": "{lowerCamelCase}"
}
}
}
}
}
Result after export for token color.primary:
- Web →
var(--color-primary) - Android →
ColorPrimary - iOS →
colorPrimary
How path conversion works: separators
/,.,_are replaced with-, then the path is split into words. Each template formats the words in the appropriate style.
Group-level inheritance
The most convenient approach is to set $extensions at the group level, so all tokens inside inherit the settings:
{
"color": {
"$extensions": {
"figma.scopes": ["ALL_FILLS", "STROKE_COLOR", "EFFECT_COLOR"],
"figma.codeSyntax": {
"Web": "{var(--css-variable)}",
"Android": "{UpperCamelCase}",
"iOS": "{lowerCamelCase}"
}
},
"primary": {
"$type": "color",
"$value": "#0066FF"
},
"secondary": {
"$type": "color",
"$value": "#6633CC"
},
"danger": {
"$type": "color",
"$value": "#FF3B30"
}
}
}
In this example all three tokens (primary, secondary, danger) will receive:
- Scopes:
ALL_FILLS,STROKE_COLOR,EFFECT_COLOR - Code Syntax via templates
Per-token override
If a specific token needs different settings, specify $extensions directly on it. Inheritance is a shallow merge: a child key replaces the same parent key, while parent keys not mentioned by the child are kept.
{
"color": {
"$extensions": {
"figma.scopes": ["ALL_FILLS", "STROKE_COLOR", "EFFECT_COLOR"],
"figma.codeSyntax": {
"Web": "{var(--css-variable)}",
"Android": "{UpperCamelCase}",
"iOS": "{lowerCamelCase}"
}
},
"primary": {
"$type": "color",
"$value": "#0066FF"
},
"text-only": {
"$type": "color",
"$value": "#333333",
"$extensions": {
"figma.scopes": ["TEXT_FILL"],
"figma.codeSyntax": {
"Web": "var(--text-body)"
}
}
}
}
}
Token color.text-only:
- Scopes → only
TEXT_FILL(notALL_FILLS+STROKE_COLOR+EFFECT_COLOR) - Code Syntax → only
Web: "var(--text-body)"(Android and iOS will not be set because thefigma.codeSyntaxvalue is replaced as a whole)
Inheritance rule:
$extensionsis merged from root/group to leaf. If a child definesfigma.scopes, it replaces parent scopes as a whole. If a child definesfigma.codeSyntax, it replaces the entire parent code syntax object. Keys not defined by the child continue to be inherited.
Additional extensions
figma.hide
Hides a variable from publishing. The variable is created in Figma but is not visible in other files when using the library.
{
"foundation": {
"base-unit": {
"$type": "number",
"$value": 4,
"$extensions": {
"figma.hide": true
}
}
}
}
Useful for foundation tokens that serve only as a base for calculations or aliases — library consumers should not see them.
figma.modify
Color modifiers — a chain of transformations for color tokens:
{
"color": {
"primary-light": {
"$type": "color",
"$value": "{color.primary}",
"$extensions": {
"figma.modify": [
{ "type": "lighten", "value": 0.2, "space": "oklch" },
{ "type": "alpha", "value": 0.8, "space": "srgb" }
]
}
}
}
}
Only four modifier types are supported:
type | What it does | Required fields |
|---|---|---|
lighten | Lightens color | value (0..1), space |
darken | Darkens color | value (0..1), space |
alpha | Changes opacity | value (0..1), space optional |
mix | Mixes with another color | value (0..1), color, space |
Supported color spaces: srgb, hsl, lch, oklch, p3.
Modifiers are applied as a top-to-bottom chain: each step takes the previous result as input.
When Scopes and Code Syntax are applied
Settings are applied during variable export to Figma, but only if the Apply codeSyntax & scopes flag is enabled in the export dialog.
Current default in Export settings: OFF.
| What happens | When |
|---|---|
| Scopes are written to the variable | On creation and update, if figma.scopes is specified |
| Code Syntax is written to the variable | On creation and update, if figma.codeSyntax is specified |
figma.hide is written | On creation and update |
| Changes are tracked in diff | Always (scopes, codeSyntax, hide are included in the diff-id hash) |
More about export in Export Variables & Styles.
Full example: design system
{
"color": {
"$extensions": {
"figma.scopes": ["ALL_FILLS", "STROKE_COLOR", "EFFECT_COLOR"],
"figma.codeSyntax": {
"Web": "{var(--css-variable)}",
"Android": "{UpperCamelCase}",
"iOS": "{lowerCamelCase}"
}
},
"brand": {
"primary": {
"$type": "color",
"$value": "#0066FF",
"$description": "Primary brand color"
},
"secondary": {
"$type": "color",
"$value": "#6633CC"
}
},
"text": {
"$extensions": {
"figma.scopes": ["TEXT_FILL"]
},
"body": {
"$type": "color",
"$value": "#333333"
},
"muted": {
"$type": "color",
"$value": "#999999"
}
}
},
"spacing": {
"$extensions": {
"figma.scopes": ["GAP"],
"figma.codeSyntax": {
"Web": "{var(--css-variable)}",
"Android": "{lowerCamelCase}",
"iOS": "{lowerCamelCase}"
}
},
"xs": { "$type": "spacing", "$value": "4px" },
"sm": { "$type": "spacing", "$value": "8px" },
"md": { "$type": "spacing", "$value": "16px" },
"lg": { "$type": "spacing", "$value": "24px" },
"xl": { "$type": "spacing", "$value": "32px" }
},
"borderRadius": {
"$extensions": {
"figma.scopes": ["CORNER_RADIUS"],
"figma.codeSyntax": {
"Web": "{var(--css-variable)}"
}
},
"sm": { "$type": "borderRadius", "$value": "4px" },
"md": { "$type": "borderRadius", "$value": "8px" },
"lg": { "$type": "borderRadius", "$value": "16px" },
"full": { "$type": "borderRadius", "$value": "9999px" }
},
"fontSize": {
"$extensions": {
"figma.scopes": ["FONT_SIZE"],
"figma.codeSyntax": {
"Web": "{var(--css-variable)}"
}
},
"sm": { "$type": "fontSize", "$value": "12px" },
"base": { "$type": "fontSize", "$value": "14px" },
"lg": { "$type": "fontSize", "$value": "18px" },
"xl": { "$type": "fontSize", "$value": "24px" }
}
}
After export:
- Colors
color.brand.*are visible in fills, strokes, and effects - Colors
color.text.*are visible only in text fills - Spacing
spacing.*is visible only in the gap field - Border radii
borderRadius.*are visible only in corner radius - Font sizes
fontSize.*are visible only in font-size - All variables display correct code syntax in Dev Mode
Tips
- Start with groups — set
$extensionsat thecolor,spacing,borderRadiuslevel. This covers 90% of cases. - Use templates —
{var(--css-variable)}for CSS,{UpperCamelCase}for Android,{lowerCamelCase}for iOS. Don't write names manually. - Hide foundation tokens — use
figma.hide: truefor base values that library consumers should not see. - Don't overuse scopes — avoid
ALL_SCOPESeverywhere. Specific scopes help designers find the right variable faster. - Check compatibility — a scope must match the variable type. Invalid scopes are silently discarded.
Related sections
- Tokens Overview — general token tab structure
- Token Types — all supported types
- Export Variables & Styles — exporting to Figma with scopes applied
- Tokens to Code — code generation based on Code Syntax