A Design Tokens Workflow (part 11)
Creating Sass-backed CSS Custom Properties With Style Dictionary
- Getting Started With Style Dictionary
- Outputting to Different Formats with Style Dictionary
- Beyond JSON: Exploring File Formats for Design Tokens
- Converting Tokens with Style Dictionary
- Organising Outputs with Style Dictionary
- Layers, referencing tokens in Style Dictionary
- Implementing Light and Dark Mode with Style Dictionary
- Implementing Light and Dark Mode with Style Dictionary (part 2)
- Implementing Multi-Brand Theming with Style Dictionary
- Creating Multiple Themes with Style Dictionary
- Creating Sass-backed CSS Custom Properties With Style Dictionary – You are here
- Creating a Penpot Design Tokens Format with Style Dictionary
On This Page:
Whilst writing my recent article on where and when I choose to use Sass variables or CSS Custom Properties in a project I thought to myself “you could automate this bit using style dictionary”. As that article is published I’ve quickly opened up a new markdown file to write this. In this tutorial we will look at how we can use our design tokens to not only generate Sass variables, but generate CSS custom properties that will make use of the Sass variables using interpolation.
Implementing Spacing Tokens
Let's create a sample token structure that combines scale definitions with component-specific applications. tokens/base/spacing.tokens
tokens/semantic/spacing.tokens
Style Dictionary Configuration
Next we need to create a new build script that will use Style Dictionary. What we want to do is:
- generate a .scssfile of the base spacing tokens as Sass variables
- generate a .scssfile of the semantic spacing tokens that will create a set of CSS custom properties that use Sass variables via interpolations (—component-margin-inline: #{$spacing-400];.
Key Script Components
- Token Aggregation: Using globSyncto recursively collect all .tokensfiles from src/tokens/**/*.tokens`.
- Smart Reference Handling: The custom css/sass-refformat automatically:- Detects any token reference format ({type.path.to.token})
- Converts dot-notation paths to Sass-friendly hyphens
- Removes . $valuesuffixes while maintaining reference integrity
 
- Detects any token reference format (
- Separation of Concerns: Platform configuration keeps base tokens (design primitives) separate from semantic tokens (contextual applications)
The code for this example can be found on this branch of the repo this series has been using
Generated Output Structure
The script produces two critical files. These files are:
- a Sass variables file that maintains design system constants.
- a CSS custom properties file that references Sass values via interpolation.
Base Tokens (Sass)
_base-tokens.scss
Semantic Tokens (CSS)
_variables.scss
This Style Dictionary configuration helps solve several challenges in modern design systems:
- Single Source of Truth: Token updates propagate through both Sass and CSS layers.
- Contextual Adaptation: Component-specific overrides maintain design consistency
- Toolchain Integration: Automates the Sass to CSS bridge while preserving both paradigms.
- Scale Maintenance: Spacing ratios remain consistent across primitive and semantic layers.
By combining Style Dictionary's transformation power with Sass's preprocessing capabilities, we can create a future-proof system that works seamlessly with CSS-in-JS solutions, traditional Sass projects, and modern CSS-only architectures and more.