Page cover

Font Fallbacks

Font fallbacks are a common practice in code to ensure the text remains readable even when the primary font is unavailable.

"A fallback font is a font face that is used when the primary font face is not loaded yet, or is missing glyphsarrow-up-right necessary to render page content. For example, the CSS below indicates that the sans-serif font family should be used as the font fallback for Roboto" - Chrome for Developersarrow-up-right

While Figma doesn't natively support font fallbacks, Tokens Studio allows you to define fallbacks for Font Family and Font Weight Token Types.


In the plugin

To define a fallback using the plugin, you can write the Token's value using the no-code or interface or modify the JSON file with comma-separated values.

Font Family Tokens

To implement font fallbacks in your Font Family Token:

  • Use a comma-separated list in your token value.

  • Write the Font name (string value) in order of preference, from primary to fallback options.

    • Be sure to follow the guidelines for best practices outlined in the Font Family Token documentation. #add-doc-link/typography

  • Figma will use the first Font Family in the list.

Example:

{
  "sans-serif": {
    "$value": "Arial, Helvetica",
    "$type": "fontFamilies"
  }
}

Typography Composite Tokens

When using Typography Composite Tokens, you can reference a Font Family Token that includes fallbacks:


Limitations and Considerations

Figma will only display the primary font, not the fallbacks.

  • When exporting to Figma variables or styles, only the primary font will be used.

  • Fallbacks are primarily for web and application development, not for use within Figma itself.

While it might be tempting to use fallbacks as a way to work around Figma's nuanced way of Font Weight + Style values as a combined string, which is written differently for each Font Family, we don't recommend this approach.

  • We will always pass the first value to Figma, so if it doesn't match, you'll still get the error even if you included the correct value as a fallback.

  • Tokens are intended to be used in code, which isn't as particular as Figma. So when you engineers receive a Font Weight Token with the same value repeated multiple times it might lead to unexpected results.


Transforming Tokens

Engineers typically transform Tokens used in code with Style Dictionaryarrow-up-right, which is tool-agnostic. Tokens coming from Tokens Studio require an additional step: @Tokens-studio/sd-transformsarrow-up-right, an npm package that prepares Tokens for Style Dictionary.

When transforming tokens for use in code, the Style Dictionary handles font fallbacks appropriately:

  • fontFamily Tokens that contain multiple values (comma separated) will be processed slightly for CSS to ensure that when a Font Family name contains spaces, the value is put in quotes ' so it works in CSS.

→ Style Dictionary - Built in Transforms fontFamily/CSSarrow-up-right


Resources

Mentioned in this doc:

CSS resources:

Community resources:

  • None yet!

💡 Something to share? Submit it here!arrow-up-right

Known issues and bugs

Tokens Studio Plugin GitHub - Tokens Studio Plugin GitHub - Open issues for Token Type Font Familyarrow-up-right

🐞 If you are experiencing an issue not listed here, please reach out to us on the Troubleshooting channel of our community Slackarrow-up-right, submit it on our feedback toolarrow-up-right, or send us an email [email protected]

Requests, roadmap and changelog

  • None

💌 Visit https://feedback.tokens.studio/ arrow-up-rightto contribute or subscribe to updates.

Last updated

Was this helpful?