This project demonstrates how to integrate design tokens from Figma into a React application using Style Dictionary and CSS variables. It is designed as a demo for developers about how to seamlessly connect their design system in Figma with their codebase, ensuring consistent and easily maintainable styles.
- How to export design tokens from Figma using a plugin.
- How to convert Figma tokens to Style Dictionary format.
- How to generate CSS variables from design tokens.
- How to use those variables in your React app for colors, typography, and more.
├── design-tokens/ # 🎨 JSON tokens exported from Figma ├── src/ │ └── styles/ │ └── tokens/ # 🏗️ Auto-generated CSS variables │ └── components/ # 🧩 Example components using tokens ├── style-dictionary.config.json # ⚙️ Style Dictionary configuration
- Organize your colors, typography, and other tokens in Figma using Styles.
- Use clear, consistent naming for your tokens.
- Install the Figma-to-Style-Dictionary JSON Converter plugin in Figma.
- Run the plugin and export your tokens as a JSON file.
- Save the exported file in the
design-tokens/directory (e.g.,design-tokens/stylesToken.json).
-
Edit
style-dictionary.config.jsonto point to your token files and define the output format (CSS variables):{ "source": ["design-tokens/**/*.json"], "platforms": { "css": { "transformGroup": "css", "buildPath": "src/styles/tokens/", "files": [ { "destination": "variables.css", "format": "css/variables", "options": { "outputReferences": true } } ] } } }This is just a basic example, but the config could be more complex. If you want to learn more visit configuration style dictionary
Run the following command to generate CSS variables from your tokens:
This will create (or update) src/styles/tokens/variables.css with all your design tokens as CSS variables.
npm run tokens-buildImport the generated CSS file in your app entry point or component:
Use the variables in your CSS or inline styles:
import "./styles/tokens/variables.css";- Now, your app uses the same design tokens as your Figma files.
- To update styles, just update tokens in Figma, export, and rebuild!
See src/App.tsx for examples of how to use color and typography tokens in components like ColorCard and Typography.
Consistency: Design and code always match. Scalability: Update tokens in Figma, sync to code in seconds. Maintainability: No more hardcoded values or manual updates. Collaboration: Designers and developers speak the same language.
- Clone this repo.
- Export your own tokens from Figma.
- Replace the JSON in design-tokens/.
- Run npm run tokens-build.
- Use your tokens in your app!
Integrate design tokens into your workflow and supercharge your design system if you found this demo helpful