Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Official Figma skill for writing directly to the Figma canvas through the MCP server and Plugin API.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
wwds-text-styles.md
1# Working with design systems: Text Styles23Text styles in Figma are named, reusable typography definitions. They are the closest equivalent to a type ramp in a design token library. A text style bundles font family, size, weight, line height, letter spacing, and other typographic properties into a single named entity that can be applied to text nodes.45Text styles are distinct from variables. You cannot put typography into a single variable — there is no composite variable type. However, individual properties on a text style _can_ be bound to variables (e.g. binding `fontSize` to a size variable, or `fontFamily` to a string variable), which allows the style to participate in a token system.67## Model89A `TextStyle` has the following writable properties:1011| Property | Type | Notes |12| ------------------ | ---------------- | ---------------------------------------------------------------------------- |13| `name` | `string` | Slash-delimited for grouping (e.g. `"Heading/XL"`) |14| `fontSize` | `number` | In pixels |15| `fontName` | `FontName` | `{ family: string, style: string }` — **font must be loaded before setting** |16| `letterSpacing` | `LetterSpacing` | `{ value: number, unit: 'PIXELS' \| 'PERCENT' }` |17| `lineHeight` | `LineHeight` | `{ value: number, unit: 'PIXELS' \| 'PERCENT' }` or `{ unit: 'AUTO' }` |18| `textCase` | `TextCase` | `'ORIGINAL' \| 'UPPER' \| 'LOWER' \| 'TITLE' \| 'SMALL_CAPS'` |19| `textDecoration` | `TextDecoration` | `'NONE' \| 'UNDERLINE' \| 'STRIKETHROUGH'` |20| `paragraphSpacing` | `number` | |21| `paragraphIndent` | `number` | |22| `description` | `string` | Inherited from `BaseStyleMixin` |2324### lineHeight and letterSpacing format2526These properties must be objects — not bare numbers:2728```js29// WRONG — bare number throws30style.lineHeight = 1.5;31style.letterSpacing = 0;3233// CORRECT34style.lineHeight = { unit: "AUTO" }; // auto line height35style.lineHeight = { value: 24, unit: "PIXELS" }; // fixed pixel height36style.lineHeight = { value: 150, unit: "PERCENT" }; // 150% line height3738style.letterSpacing = { value: 0, unit: "PIXELS" }; // zero tracking39style.letterSpacing = { value: -2, unit: "PIXELS" }; // tight tracking40style.letterSpacing = { value: 5, unit: "PERCENT" }; // percent-based tracking41```4243When reading a `lineHeight` back, always check `unit` first — `{ unit: 'AUTO' }` has no `value` key.4445### Variable bindings on text styles4647The following fields can be bound to variables via `style.setBoundVariable(field, variable)`:4849`fontFamily`, `fontSize`, `fontStyle`, `fontWeight`, `letterSpacing`, `lineHeight`, `paragraphSpacing`, `paragraphIndent`5051To unbind: `style.setBoundVariable(field, null)`5253**Important: `setBoundVariable` is NOT available on `TextStyle` in headless `use_figma` mode.**5455It is only available in interactive plugin context (UI plugins, Figma editor). When running through `use_figma` (MCP, assistant headless runtime), calling `ts.setBoundVariable(...)` will throw `"not a function"`. In this context, set raw values directly instead:5657```js58// In use_figma (headless) — variable binding not available59const ts = figma.createTextStyle();60ts.fontSize = 24; // set directly; cannot bind to a variable6162// In a real interactive plugin — variable binding works63const ts = figma.createTextStyle();64ts.setBoundVariable("fontSize", fontSizeVariable);65```6667If live variable binding on text styles is required, the recommended approach is to:68691. Create the text styles with raw values via `use_figma`702. Open the file in Figma and bind variables interactively via the Styles panel, OR713. Use an interactive plugin that runs in the Figma editor (not headless)7273### Applying a text style to a node7475Once you have a `TextStyle`, apply it to a `TextNode` by assigning its `id` to the node's `textStyleId` property. You can also use the async setter `setTextStyleIdAsync(id)`. Setting `textStyleId` on a node does **not** require the font to be loaded — only editing the text content or font properties directly does.7677## Common gotchas7879- **Font must be loaded before setting `fontName`**: Call `await figma.loadFontAsync({ family, style })` before creating or modifying a text style's font.80- **Font style names are file-dependent**: Font style names like `"SemiBold"` vs `"Semi Bold"` vary by font provider and Figma file. Always probe by calling `loadFontAsync` and catching errors to discover the correct style string rather than guessing.81- **`setBoundVariable` not available headless**: `TextStyle.setBoundVariable()` throws `"not a function"` in `use_figma` / headless mode. Set raw values instead and bind interactively if needed.82- **Styles are not automatically applied**: Creating a `TextStyle` has no effect on any node until you assign its ID to a text node.83- **`getLocalTextStyles()` is deprecated**: Always use `getLocalTextStylesAsync()`.84- **Names are not unique**: Two text styles can share the same name. Match by ID or `key` when looking up a known style, not by name alone.85- **Slash grouping is visual only**: `"Heading/XL"` and `"HeadingXL"` are different names; the slash is just a UI affordance.86- **`lineHeight` and `letterSpacing` must be objects**: `style.lineHeight = 1.5` throws. Always use `{ value, unit }` format or `{ unit: 'AUTO' }`.8788## Code patterns8990For runnable code examples (listing, creating, probing fonts, type ramps, applying styles), see [text-style-patterns.md](../text-style-patterns.md).91