Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Resources
  2. Parser Rules templates

CSS Custom Properties

This template is dedicated for Web developers using CSS. It helps you generate all types of design tokens as CSS Custom Properties in their respective CSS file and it helps you to optimize your SVG's.

PreviousParser Rules templatesNextTailwind

Last updated 1 year ago

Was this helpful?

This example uses 5 different parsers:

  • to target specific token types like colors and text styles

  • to convert our colors in HSL

  • to change the name of our tokens and modes to kebabCase

  • to generate a CSS file containing our tokens

  • to make our text styles' line-height relative to their font-size

  • to convert our text styles' font-size from px to rem

  • to generate our text styles as CSS classes

  • to optimize, transform vectors, and generate SVG files

This template is an example among others. Head toward the page to get all available options.

When using the CLI, you need to fill three properties:

  • repository is @organization/repository

  • personalAccessToken which you can generate

  • rules lets you transform tokens by chaining parsers

.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Generate colors in HSL",
      "parsers": [
        {
          "name": "filter",
          "options": {
            "query": {
              "where": {
                "token": ".*",
                "withTypes": {
                  "include": [
                    "color"
                  ]
                },
                "select": {
                  "parents": true
                }
              }
            }
          }
        },
        {
          "name": "convert-color",
          "options": {
            "toFormat": "hsl",
            "applyTo": {
              "collection": true
            }
          }
        },
        {
          "name": "change-case",
          "options": {
            "change": "names",
            "toCase": "kebabCase",
            "applyTo": {
              "collection": true
            }
          }
        },
        {
          "name": "change-case",
          "options": {
            "change": "modes",
            "toCase": "kebabCase",
            "applyTo": {
              "collection": true
            }
          }
        },
        {
          "name": "to-css-custom-properties",
          "output": {
            "type": "file",
            "filePath": "output/colors.css"
          }
        }
      ]
    },
    {
      "name": "Generate text styles as CSS classes",
      "parsers": [
        {
          "name": "filter",
          "options": {
            "query": {
              "where": {
                "token": ".*",
                "withTypes": {
                  "include": [
                    "textStyle"
                  ]
                },
                "select": {
                  "token": true
                }
              }
            }
          }
        },
        {
          "name": "change-case",
          "options": {
            "toCase": "kebabCase",
            "applyTo": {
              "token": true
            }
          }
        },
        {
          "name": "make-line-height-relative",
          "options": {}
        },
        {
          "name": "convert-dimension",
          "options": {
            "applyToKeys": {
              "textStyle": [
                "fontSize"
              ]
            },
            "toFormat": "rem"
          }
        },   
        {
          "name": "to-css-text-style",
          "output": {
            "type": "file",
            "filePath": "output/text-styles.scss"
          },
          "options": {
            "genericFamily": "sans-serif",
            "tokenNameTemplate": "text-style-{{token}}"
          }
        }
      ]
    },
    {
      "name": "Optimize and transform vectors with svgo + Generate SVG files",
      "parsers": [
        {
          "name": "svgo",
          "output": {
            "type": "directory",
            "directoryPath": "output/assets"
          },
          "options": {
            "svgo": {
              "plugins": [
                {
                  "name": "removeDimensions"
                },
                {
                  "name": "convertColors",
                  "params": {
                    "currentColor": true
                  }
                }
              ]
            }
          }
        }
      ]
    }
  ]
}

If you use the GitHub, you need to fill 4 properties:

  • repository is @organization/repository

  • head lets you set the branch your PR will be created on

  • base lets you set the branch your PR will be merged on

  • rules lets you transform tokens by chaining parsers

.specifyrc.json
{
  "version": "2",
  "head": "specifyrc-json",
  "base": "main",
  "repository": "@organization/repository",
  "rules": [
    {
      "name": "Generate colors in HSL",
      "parsers": [
        {
          "name": "filter",
          "options": {
            "query": {
              "where": {
                "token": ".*",
                "withTypes": {
                  "include": [
                    "color"
                  ]
                },
                "select": {
                  "parents": true
                }
              }
            }
          }
        },
        {
          "name": "convert-color",
          "options": {
            "toFormat": "hsl",
            "applyTo": {
              "collection": true
            }
          }
        },
        {
          "name": "change-case",
          "options": {
            "change": "names",
            "toCase": "kebabCase",
            "applyTo": {
              "collection": true
            }
          }
        },
        {
          "name": "change-case",
          "options": {
            "change": "modes",
            "toCase": "kebabCase",
            "applyTo": {
              "collection": true
            }
          }
        },
        {
          "name": "to-css-custom-properties",
          "output": {
            "type": "file",
            "filePath": "tokens.css"
          }
        }
      ]
    },
    {
      "name": "Generate text styles as CSS classes",
      "parsers": [
        {
          "name": "filter",
          "options": {
            "query": {
              "where": {
                "token": ".*",
                "withTypes": {
                  "include": [
                    "textStyle"
                  ]
                },
                "select": {
                  "token": true
                }
              }
            }
          }
        },
        {
          "name": "change-case",
          "options": {
            "toCase": "kebabCase",
            "applyTo": {
              "token": true
            }
          }
        },
        {
          "name": "make-line-height-relative",
          "options": {}
        },
        {
          "name": "convert-dimension",
          "options": {
            "applyToKeys": {
              "textStyle": [
                "fontSize"
              ]
            },
            "toFormat": "rem"
          }
        },   
        {
          "name": "to-css-text-style",
          "output": {
            "type": "file",
            "filePath": "public/text-styles.scss"
          },
          "options": {
            "genericFamily": "sans-serif",
            "tokenNameTemplate": "text-style-{{token}}"
          }
        }
      ]
    },
    {
      "name": "Optimize and transform vectors with svgo + Generate SVG files",
      "parsers": [
        {
          "name": "svgo",
          "output": {
            "type": "directory",
            "directoryPath": "output/assets"
          },
          "options": {
            "svgo": {
              "plugins": [
                {
                  "name": "removeDimensions"
                },
                {
                  "name": "convertColors",
                  "params": {
                    "currentColor": true
                  }
                }
              ]
            }
          }
        }
      ]
    }
  ]
}

Make sure you have connected your GitHub account with your Specify account. Head toward to learn more.

filter
convert-color
change-case
to-css-custom-properties
make-line-height-relative
convert-dimension
to-css-text-style
svgo
to-css-custom-properties
in your account settings
this article