Built-in transforms
attribute/cti
Section titled “attribute/cti”Adds: category, type, item, subitem, and state on the attributes object based on the location in the style dictionary.
// Matches: all// Returns:{ "category": "color", "type": "background", "item": "button", "subitem": "primary", "state": "active"}attribute/color
Section titled “attribute/color”Adds: hex, hsl, hsv, rgb, red, blue, green.
// Matches: token.type === 'color'// Returns{ "hex": "009688", "rgb": {"r": 0, "g": 150, "b": 136, "a": 1}, "hsl": {"h": 174.4, "s": 1, "l": 0.294, "a": 1}, "hsv": {"h": 174.4, "s": 1, "l": 0.588, "a": 1},}name/human
Section titled “name/human”Creates a human-friendly name
// Matches: All// Returns:'button primary';name/camel
Section titled “name/camel”Creates a camel case name. If you define a prefix on the platform in your config, it will prepend with your prefix
// Matches: all// Returns:'colorBackgroundButtonPrimaryActive';'prefixColorBackgroundButtonPrimaryActive';name/kebab
Section titled “name/kebab”Creates a kebab case name. If you define a prefix on the platform in your config, it will prepend with your prefix
// Matches: all// Returns:'color-background-button-primary-active';'prefix-color-background-button-primary-active';name/snake
Section titled “name/snake”Creates a snake case name. If you define a prefix on the platform in your config, it will prepend with your prefix
// Matches: all// Returns:'color_background_button_primary_active';'prefix_color_background_button_primary_active';name/constant
Section titled “name/constant”Creates a constant-style name based on the full CTI of the token. If you define a prefix on the platform in your config, it will prepend with your prefix
// Matches: all// Returns:'COLOR_BACKGROUND_BUTTON_PRIMARY_ACTIVE';'PREFIX_COLOR_BACKGROUND_BUTTON_PRIMARY_ACTIVE';name/pascal
Section titled “name/pascal”Creates a Pascal case name. If you define a prefix on the platform in your config, it will prepend with your prefix
// Matches: all// Returns:'ColorBackgroundButtonPrimaryActive';'PrefixColorBackgroundButtonPrimaryActive';color/rgb
Section titled “color/rgb”Transforms the value into an RGB string
// Matches: token.type === 'color'// Returns:'rgb(0, 150, 136)';color/hsl
Section titled “color/hsl”Transforms the value into an HSL string or HSLA if alpha is present. Better browser support than color/hsl-4
// Matches: token.type === 'color'// Returns:'hsl(174, 100%, 29%)';'hsl(174, 100%, 29%, .5)';color/hsl-4
Section titled “color/hsl-4”Transforms the value into an HSL string, using fourth argument if alpha is present.
// Matches: token.type === 'color'// Returns:'hsl(174 100% 29%)';'hsl(174 100% 29% / .5)';color/hex
Section titled “color/hex”Transforms the value into an 6-digit hex string
// Matches: token.type === 'color'// Returns:'#009688';color/hex8 Deprecated
Section titled “color/hex8 ”Use color/hex instead, which also supports hex8.
Transforms the value into an 8-digit hex string
// Matches: token.type === 'color'// Returns:'#009688ff';color/hex8android
Section titled “color/hex8android”Transforms the value into an 8-digit hex string for Android because they put the alpha channel first
// Matches: token.type === 'color'// Returns:'#ff009688';color/composeColor
Section titled “color/composeColor”Transforms the value into a Color class for Compose
// Matches: token.type === 'color'// Returns:Color(0xFF009688)color/UIColor
Section titled “color/UIColor”Transforms the value into an UIColor class for iOS
// Matches: token.type === 'color'// Returns:[UIColor colorWithRed:0.114f green:0.114f blue:0.114f alpha:1.000f]color/UIColorSwift
Section titled “color/UIColorSwift”Transforms the value into an UIColor swift class for iOS
// Matches: token.type === 'color'// Returns:UIColor(red: 0.667, green: 0.667, blue: 0.667, alpha: 0.6)color/ColorSwiftUI
Section titled “color/ColorSwiftUI”Transforms the value into an UIColor swift class for iOS
// Matches: token.type === 'color'// Returns:Color(red: 0.667, green: 0.667, blue: 0.667, opacity: 0.6)color/css
Section titled “color/css”Transforms the value into a hex or rgb string depending on if it has transparency
// Matches: token.type === 'color'// Returns:#000000rgba(0,0,0,0.5)color/sketch
Section titled “color/sketch”Transforms a color into an object with red, green, blue, and alpha attributes that are floats from 0 - 1. This object is how Sketch stores colors.
// Matches: token.type === 'color'// Returns:{ red: 0.5, green: 0.5, blue: 0.5, alpha: 1}size/sp
Section titled “size/sp”Transforms the value into a scale-independent pixel (sp) value for font sizes on Android. It will not scale the number.
// Matches: token.type === 'fontSize'// Returns:'10.0sp';size/dp
Section titled “size/dp”Transforms the value into a density-independent pixel (dp) value for non-font sizes on Android. It will not scale the number.
// Matches: token.type === 'dimension'// Returns:'10.0dp';size/object
Section titled “size/object”Transforms the value into a useful object ( for React Native support )
// Matches: token.type === 'dimension'// Returns:{ original: "10px", number: 10, decimal: 0.1, // 10 divided by 100 scale: 160, // 10 times 16}size/remToSp
Section titled “size/remToSp”Transforms the value from a REM size on web into a scale-independent pixel (sp) value for font sizes on Android. It WILL scale the number by a factor of 16 (or the value of basePxFontSize on the platform in your config).
// Matches: token.type === 'fontSize'// Returns:'16.0sp';size/remToDp
Section titled “size/remToDp”Transforms the value from a REM size on web into a density-independent pixel (dp) value for font sizes on Android. It WILL scale the number by a factor of 16 (or the value of basePxFontSize on the platform in your config).
// Matches: token.type === 'fontSize'// Returns:'16.0dp';size/px
Section titled “size/px”Adds ‘px’ to the end of the number. Does not scale the number
// Matches: token.type === 'dimension'// Returns:'10px';size/rem
Section titled “size/rem”Adds ‘rem’ to the end of the number. Does not scale the number.
// Matches: token.type === 'dimension'// Returns:'10rem';size/remToFloat
Section titled “size/remToFloat”Scales the number and adds ‘f’ to the end.
The default basePxFontSize scale is 16, which can be configured on the platform in your config.
// Matches: token.type === 'dimension'// Returns:'16f';Configuring the basePxFontSize:
{ "platforms": { "css": { "transforms": ["size/remToFloat"], "basePxFontSize": 14 } }}size/remToPt
Section titled “size/remToPt”Scales the number and adds ‘pt’ to the end.
The default basePxFontSize scale is 16, which can be configured on the platform in your config.
// Matches: token.type === 'dimension'// Returns:'16pt';Configuring the basePxFontSize:
{ "platforms": { "css": { "transforms": ["size/remToSp"], "basePxFontSize": 14 } }}size/compose/remToSp
Section titled “size/compose/remToSp”Transforms the value from a REM size on web into a scale-independent pixel (sp) value for font sizes in Compose. It WILL scale the number by a factor of 16 (or the value of basePxFontSize on the platform in your config).
// Matches: token.type === 'fontSize'// Returns:"16.0.sp"size/compose/remToDp
Section titled “size/compose/remToDp”Transforms the value from a REM size on web into a density-independent pixel (dp) value for font sizes in Compose. It WILL scale the number by a factor of 16 (or the value of basePxFontSize on the platform in your config).
// Matches: token.type === 'dimension'// Returns:"16.0.dp"size/compose/em
Section titled “size/compose/em”Adds the .em Compose extension to the end of a number. Does not scale the value
// Matches: token.type === 'fontSize'// Returns:"16.0em"size/compose/sp
Section titled “size/compose/sp”Adds the .sp Compose extension to the end of a number. Does not scale the value
// Matches: token.type === 'fontSize'// Returns:"16.0.sp"size/compose/dp
Section titled “size/compose/dp”Adds the .dp Compose extension to the end of a number. Does not scale the value
// Matches: token.type === 'dimension'// Returns:"16.0.dp"size/swift/remToCGFloat
Section titled “size/swift/remToCGFloat”Scales the number by 16 (or the value of basePxFontSize on the platform in your config) to get to points for Swift and initializes a CGFloat
// Matches: token.type === 'dimension'// Returns: "CGFloat(16.00)""size/remToPx
Section titled “size/remToPx”Scales the number by 16 (or the value of basePxFontSize on the platform in your config) and adds ‘px’ to the end.
// Matches: token.type === 'dimension'// Returns:'16px';size/pxToRem
Section titled “size/pxToRem”Scales non-zero numbers to rem, and adds ‘rem’ to the end. If you define a “basePxFontSize” on the platform in your config, it will be used to scale the value, otherwise 16 (default web font size) will be used.
// Matches: token.type === 'dimension'// Returns:'0';'1rem';html/icon
Section titled “html/icon”Takes an HTML entity and transforms it into a form CSS can use.
// Matches: token.type === 'html'// Returns:"'\\E001'";content/quote
Section titled “content/quote”Wraps the value in a single quoted string
// Matches: token.type === 'content'// Returns:"'string'";content/objC/literal
Section titled “content/objC/literal”Wraps the value in a double-quoted string and prepends an ’@’ to make a string literal.
// Matches: token.type === 'content'// Returns:**"string"**:content/swift/literal
Section titled “content/swift/literal”Wraps the value in a double-quoted string to make a string literal.
// Matches: token.type === 'content'// Returns:"string"time/seconds
Section titled “time/seconds”Turns time and duration type tokens into seconds.
Values may be written as a DTCG object
{ "value": 200, "unit": "ms" }, as a string such as "200ms", or as a unitless number.
A value without a unit is interpreted as milliseconds. A value that is already in seconds is
no longer divided a second time.
The output uses the minimum amount of decimals that keeps the precision of the input, so a 1ms
duration resolves to 0.001s rather than being rounded away to 0s, and a value that needs no
decimals is not padded with them.
// Matches: token.type === 'time' || token.type === 'duration'// Returns:'0.5s'; // from value 500, or { value: 500, unit: 'ms' }'0.001s'; // from { value: 1, unit: 'ms' }'1000s'; // from { value: 1000000, unit: 'ms' }fontFamily/css
Section titled “fontFamily/css”Transforms fontFamily type token (which can be an array) into a CSS string, putting single quotes around font names that contain spaces where necessary.
Also handles the fontFamily property inside typography type object-values.
/** * Matches: token.type === 'fontFamily' || token.type === 'typography' * Returns: */:root { --var: 'Arial Black', Helvetica, sans-serif;}cubicBezier/css
Section titled “cubicBezier/css”Transforms cubicBezier type token into a CSS string, using the CSS cubic-bezier function.
Also handles the timingFunction property inside transition type object-values.
/** * Matches: token.type === 'cubicBezier' || token.type === 'transition' * Returns: */:root { --var: cubic-bezier(0, 0, 0.5, 1);}strokeStyle/css/shorthand
Section titled “strokeStyle/css/shorthand”Transforms strokeStyle type object-value token into a CSS string, using the CSS dashed fallback.
/** * Matches: token.type === 'strokeStyle' * Returns: */:root { --var: dashed;}border/css/shorthand
Section titled “border/css/shorthand”Transforms border type object-value token into a CSS string, using the CSS border shorthand notation.
/** * Matches: token.type === 'border' * Returns: */:root { --var: 2px solid #000000;}When using DTCG color object definition for the color property, it will auto-convert it to a CSS compatible string if available in the color space in which it is defined.
typography/css/shorthand
Section titled “typography/css/shorthand”Transforms typography type object-value token into a CSS string, using the CSS font shorthand notation.
/** * Matches: token.type === 'typography' * Returns: */:root { --var: italic 400 1.2rem/1.5 'Fira Sans', sans-serif;}transition/css/shorthand
Section titled “transition/css/shorthand”Transforms transition type object-value token into a CSS string, using the CSS transition shorthand notation.
The duration and delay properties may be duration values or references to duration tokens, and are
stringified with their unit, so { "value": 200, "unit": "ms" } becomes 200ms.
/** * Matches: token.type === 'transition' * Returns: */:root { --var: 200ms ease-in-out 50ms;}shadow/css/shorthand
Section titled “shadow/css/shorthand”Transforms shadow type object-value token (which can also be an array) into a CSS string, using the CSS shadow shorthand notation.
/** * Matches: token.type === 'shadow' * Returns: */:root { --var: 2px 4px 8px 10px #000000, 1px 1px 4px #cccccc;}When using DTCG color object definition for the color property, it will auto-convert it to a CSS compatible string if available in the color space in which it is defined.
asset/url
Section titled “asset/url”Wraps the value in a CSS url() function
// Matches: token.type === 'asset'// Returns:url('https://www.example.com/style.css');asset/base64
Section titled “asset/base64”Reads the file at the path in the token’s value and replaces the value with the file’s contents encoded as base64. The result is not wrapped in quotes, so add them where your output needs a string, e.g. in a custom transform or in the code that consumes the token.
// Matches: token.type === 'asset'// Returns:IyBlZGl0b3Jjb25maWcub3JnCnJvb3QgPSB0cnVlCgpbKl0KaW5kZW50X3N0eWxlID0gc3BhY2UKaW5kZW50X3NpemUgPSAyCmVuZF9vZl9saW5lID0gbGYKY2hhcnNldCA9IHV0Zi04CnRyaW1fdHJhaWxpbmdfd2hpdGVzcGFjZSA9IHRydWUKaW5zZXJ0X2ZpbmFsX25ld2xpbmUgPSB0cnVlCgpbKi5tZF0KdHJpbV90cmFpbGluZ193aGl0ZXNwYWNlID0gZmFsc2U=asset/path
Section titled “asset/path”Prepends the local file path
// Matches: token.type === 'asset'// Returns:'path/to/file/asset.png';asset/objC/literal
Section titled “asset/objC/literal”Wraps the value in a double-quoted string and prepends an ’@’ to make a string literal.
// Matches: token.type === 'asset'// Returns: @"string"asset/swift/literal
Section titled “asset/swift/literal”Wraps the value in a double-quoted string to make a string literal.
// Matches: token.type === 'asset'// Returns: "string"color/hex8flutter
Section titled “color/hex8flutter”Transforms the value into a Flutter Color object using 8-digit hex with the alpha chanel on start
// Matches: token.type === 'color'// Returns:Color(0xff00ff5f);content/flutter/literal
Section titled “content/flutter/literal”Wraps the value in a double-quoted string to make a string literal.
// Matches: token.type === 'content'// Returns: "string"asset/flutter/literal
Section titled “asset/flutter/literal”Wraps the value in a double-quoted string to make a string literal.
// Matches: token.type === 'asset'// Returns: "string"size/flutter/remToDouble
Section titled “size/flutter/remToDouble”Scales the number by 16 (or the value of basePxFontSize on the platform in your config) to get to points for Flutter
// Matches: token.type === 'dimension'