EduFlow

Section 4 · Tooling and Delivery

Figma Variables and Libraries, in Sync with Code

20 min3 min readPut in order

Lesson at a glance

Mirror your token tiers in Figma variable collections and modes, publish them through libraries, and run one sync process so design files and code never disagree about a value.

  1. 1Mapping tiers to Figma variables
  2. 2Make the right variable the easy one
  3. 3The sync loop

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

For eight months after we launched tokens, Northwind had two truths. The JSON in the repository said the action blue was #1f5ae0; the Figma library said #2160e8, because a designer had nudged it for a campaign mockup and published. Engineers built from the inspect panel, so the marketing site shipped one blue and the app another. Tokens solve consistency only if design files and code read from the same decisions.

Mapping tiers to Figma variables

Figma variables hold reusable values such as colors and numbers, grouped into collections. A collection can have several modes, each giving every variable in the collection a different value. A variable can also alias another variable. That’s enough to mirror the token architecture almost one to one:

Token concept Figma
Primitive tier Collection “Primitives”, one mode
Semantic tier Collection “Semantic”, modes Light and Dark
Density Collection “Density”, modes Comfortable and Compact
Brand An extended collection per brand (Enterprise), or a Brand collection with modes
Alias {color.blue.600} Variable aliasing blue/600

Variable names use slashes to form groups, so color/action/bg appears as a group path in the picker and corresponds to the token color.action.bg. Figma frames pick modes the way the CSS attribute selectors do: a frame can set a mode explicitly, and anything inside it on Auto inherits that mode, so a dark hero frame on a light page works just like data-theme="dark" on a section.

For brands, Figma’s extended collections, available on the Enterprise plan, let you create a Tidewater collection that inherits from the Northwind semantic collection and overrides only the brand variables. Updates to variables that Tidewater didn’t override flow through automatically. On other plans, a separate Brand collection with one mode per brand gets you most of the way.

Make the right variable the easy one

Two settings matter more than any naming scheme. First, hide primitives from publishing. The semantic collection can still alias them, but designers in product files only see semantic variables, which is exactly the rule components follow in code. Second, give every published variable code syntax: Dev Mode then shows var(--nw-color-action-bg) instead of a hex value, so what the designer picked is literally what the engineer types. Scoping helps too: restrict color variables to the properties they’re meant for, so a text color doesn’t appear in the fill picker.

The sync loop

A loop: a designer proposes a change in a Figma branch, exports JSON into a pull request, CI checks and builds, the release is published, and the released JSON is imported back into the Figma library. Figma branch proposal Pull request tokens JSON CI checks build outputs Release Figma library import, publish released JSON
One source of truth, with Figma as a synced mirror

Designers still design in Figma; they just don’t publish token values directly. A change starts in a branch of the library file (branching is available on Figma’s Organization and Enterprise plans), where the designer can try it in real mockups. When it’s ready, the changed modes are exported as JSON: Figma can export and import a collection’s modes in the DTCG format. The export becomes a pull request against the tokens repository, where CI runs the checks from Section 2 and a core designer and engineer review it. After release, the released JSON is imported into the main library file and the library update is published.

Some teams automate the last step with a plugin or Figma’s REST API. Northwind does it by hand once per release; it takes ten minutes, and a human glancing at the variables panel has caught two bad imports.

The same loop works for components, with Code Connect linking Figma components to their code in Dev Mode. In the exercise, you put the steps of a token change in order. Next, you version those releases so teams know what an update will do to them.

Key takeaways

  • Map token tiers to Figma variable collections, and map themes, brands and density to modes or extended collections.
  • Pick one source of truth for token values and make the other side a mirror that is updated by a defined process, never by hand.
  • Give semantic variables code syntax and hide primitives from publishing, so designers pick the same names engineers type.
  • Library updates are releases too; designers accept them in their files the way engineers bump a package version.

Further reading

Check your understanding

3 questions

Question 1 of 3

Northwind’s designers can pick any primitive like blue/600 from the library, and mockups keep using primitives where semantic tokens belong. What’s the best fix?

Question 2 of 3

A designer changed color/action/bg in Figma last week, and an engineer changed the same token in the JSON yesterday, to a different value. What process failure does this show?

Question 3 of 3

How should Northwind represent its two brands in Figma on an Enterprise plan?

Practice

Put in order

Ship a token change from Figma to code and back

A Northwind designer wants to darken color/text/subtle because it fails contrast in the Tidewater dark theme. The JSON in the tokens repository is the source of truth, and the Figma library is a mirror. Put the steps of the change in order.

Use the arrow buttons to reorder.

  1. 1Export the changed modes as DTCG JSON and open a pull request in the tokens repository
  2. 2A core designer and engineer review the pull request and its visual diffs
  3. 3CI runs the naming, reference and contrast checks and builds CSS, Swift and Kotlin
  4. 4Merge and publish a new tokens version with a changelog entry
  5. 5Import the released JSON into the main library’s variables and publish the library update
  6. 6Designer tries the darker value in a branch of the Figma library file