Tokens

Scopes and Code Syntax

Where a variable is offered in Figma and how it is named in Dev Mode: the Scopes and Code Syntax sections of the token form, the $extensions field in JSON, allowed scopes per variable kind, code syntax templates and inheritance.

Two variable settings are set in the token form and stored in $extensions:

SettingControls
Scopes (figma.scopes)In which Figma fields the variable is offered
Code Syntax (figma.codeSyntax)How the variable is named in Dev Mode for the Web, Android and iOS platforms

Both are optional and affect only types that export as variables. Styles and internal types have no such sections. They are written to Figma when the Apply codeSyntax & scopes switch in the Export to Figma window is on, which it is by default.

JSON
{
  "color": {
    "brand": {
      "$type": "color",
      "$value": "#635BFF",
      "$extensions": {
        "figma.scopes": ["ALL_FILLS", "STROKE_COLOR"],
        "figma.codeSyntax": { "Web": "var(--color-brand)", "iOS": "Color.brand" }
      }
    }
  }
}

Where to set them

  • In the create or edit form of a token: the Scopes and Code Syntax sections.
  • For many tokens at once: in the collection table select rows and choose Edit token fields… in the context menu, which has the same Scopes and the Code Syntax fields for Web, iOS and Android. Inherit from group… restores inheritance from the group. See Collections.
  • In JSON: the $extensions field of a token or a group.

Scopes

A scope limits the Figma fields in which a variable is offered. The set of allowed scopes depends on the variable kind the token type exports to.

Variable kindToken types
Colorcolor
Numberopacity, dimension, number, spacing, sizing, borderWidth, borderRadius, fontSize, lineHeight, letterSpacing, paragraphSpacing, paragraphIndent
StringfontFamily, fontWeight, text
Booleanboolean
Timingduration
EasingcubicBezier, easing

Allowed scopes per kind

Other values are treated as an error by the editor and are not written to Figma.

KindAllowed figma.scopes
ColorALL_SCOPES, ALL_FILLS, FRAME_FILL, SHAPE_FILL, TEXT_FILL, STROKE_COLOR, EFFECT_COLOR
NumberALL_SCOPES, TEXT_CONTENT, CORNER_RADIUS, WIDTH_HEIGHT, GAP, STROKE_FLOAT, EFFECT_FLOAT, OPACITY, FONT_SIZE, LINE_HEIGHT, LETTER_SPACING, PARAGRAPH_SPACING, PARAGRAPH_INDENT, FONT_WEIGHT
StringALL_SCOPES, TEXT_CONTENT, FONT_FAMILY, FONT_STYLE
Boolean, Timing, EasingScopes are not supported; the field must be absent or empty

ALL_SCOPES means "everywhere" and cannot be combined with other values. For fontWeight only FONT_STYLE is allowed: Figma stores the face as a string, so the FONT_WEIGHT scope does not fit it and causes a file validation error.

Default scopes

If figma.scopes is not set, the plugin picks a scope by type. Variable types not in the table get ALL_SCOPES.

$typeDefault scope
colorALL_FILLS, STROKE_COLOR, EFFECT_COLOR
sizingWIDTH_HEIGHT
spacingGAP
borderRadiusCORNER_RADIUS
borderWidthSTROKE_FLOAT
opacityOPACITY
fontFamilyFONT_FAMILY
fontWeightFONT_STYLE
fontSizeFONT_SIZE
lineHeightLINE_HEIGHT
letterSpacingLETTER_SPACING
paragraphSpacingPARAGRAPH_SPACING
paragraphIndentPARAGRAPH_INDENT
dimension, number, textALL_SCOPES
JSON
{
  "spacing": {
    "$type": "spacing",
    "md": { "$value": "16px", "$extensions": { "figma.scopes": ["GAP", "WIDTH_HEIGHT"] } }
  }
}

Code Syntax

figma.codeSyntax sets the string that Dev Mode shows next to the variable, separately per platform. All keys are optional.

KeyPlatformExample
WebCSS, SCSS, Lessvar(--color-brand), $color-brand
AndroidKotlin, XMLColorBrand, @color/brand
iOSSwift, SwiftUIColor.brand, UIColor.brand
JSON
{
  "$extensions": {
    "figma.codeSyntax": { "Web": "var(--color-brand)", "Android": "@color/brand", "iOS": "Color.brand" }
  }
}

Templates

Instead of a name for every token, set a template: the plugin builds the name from the token path.

TemplateResult 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
JSON
{
  "$extensions": {
    "figma.codeSyntax": { "Web": "{var(--css-variable)}", "Android": "{UpperCamelCase}", "iOS": "{lowerCamelCase}" }
  }
}

The path is split into words at the /, . and _ separators, and the template joins the words in its style.

Inheritance

Set $extensions on a group, and every token inside inherits it. A token may override an individual key; the other keys are merged.

JSON
{
  "color": {
    "$type": "color",
    "$extensions": { "figma.scopes": ["ALL_FILLS", "STROKE_COLOR"] },
    "brand": { "$value": "#635BFF" },
    "brand-strong": {
      "$value": "{color.brand}",
      "$extensions": { "figma.scopes": ["STROKE_COLOR"] }
    }
  }
}

The token badge tooltip shows that settings are inherited from the group.

Full example

JSON
{
  "color": {
    "$type": "color",
    "$extensions": { "figma.scopes": ["ALL_FILLS", "STROKE_COLOR"], "figma.codeSyntax": { "Web": "{var(--css-variable)}" } },
    "brand": {
      "primary": { "$value": "#635BFF" },
      "on-primary": { "$value": "#FFFFFF", "$extensions": { "figma.scopes": ["TEXT_FILL"] } }
    }
  },
  "radius": {
    "$type": "borderRadius",
    "md": { "$value": "8px", "$extensions": { "figma.scopes": ["CORNER_RADIUS"] } }
  }
}