Skip to content

Built-in transforms

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"
}

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},
}

Creates a human-friendly name

// Matches: All
// Returns:
'button primary';

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';

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';

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';

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';

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';

Transforms the value into an RGB string

// Matches: token.type === 'color'
// Returns:
'rgb(0, 150, 136)';

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)';

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)';

Transforms the value into an 6-digit hex string

// Matches: token.type === 'color'
// Returns:
'#009688';

Use color/hex instead, which also supports hex8.

Transforms the value into an 8-digit hex string

// Matches: token.type === 'color'
// Returns:
'#009688ff';

Transforms the value into an 8-digit hex string for Android because they put the alpha channel first

// Matches: token.type === 'color'
// Returns:
'#ff009688';

Transforms the value into a Color class for Compose

// Matches: token.type === 'color'
// Returns:
Color(0xFF009688)

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]

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)

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)

Transforms the value into a hex or rgb string depending on if it has transparency

// Matches: token.type === 'color'
// Returns:
#000000
rgba(0,0,0,0.5)

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
}

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';

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';

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
}

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';

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';

Adds ‘px’ to the end of the number. Does not scale the number

// Matches: token.type === 'dimension'
// Returns:
'10px';

Adds ‘rem’ to the end of the number. Does not scale the number.

// Matches: token.type === 'dimension'
// Returns:
'10rem';

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:

config.json
{
"platforms": {
"css": {
"transforms": ["size/remToFloat"],
"basePxFontSize": 14
}
}
}

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:

config.json
{
"platforms": {
"css": {
"transforms": ["size/remToSp"],
"basePxFontSize": 14
}
}
}

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"

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"

Adds the .em Compose extension to the end of a number. Does not scale the value

// Matches: token.type === 'fontSize'
// Returns:
"16.0em"

Adds the .sp Compose extension to the end of a number. Does not scale the value

// Matches: token.type === 'fontSize'
// Returns:
"16.0.sp"

Adds the .dp Compose extension to the end of a number. Does not scale the value

// Matches: token.type === 'dimension'
// Returns:
"16.0.dp"

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)""

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';

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';

Takes an HTML entity and transforms it into a form CSS can use.

// Matches: token.type === 'html'
// Returns:
"'\\E001'";

Wraps the value in a single quoted string

// Matches: token.type === 'content'
// Returns:
"'string'";

Wraps the value in a double-quoted string and prepends an ’@’ to make a string literal.

// Matches: token.type === 'content'
// Returns:
**"string"**:

Wraps the value in a double-quoted string to make a string literal.

// Matches: token.type === 'content'
// Returns:
"string"

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' }

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.

DTCG definition

/**
* Matches: token.type === 'fontFamily' || token.type === 'typography'
* Returns:
*/
:root {
--var: 'Arial Black', Helvetica, sans-serif;
}

Transforms cubicBezier type token into a CSS string, using the CSS cubic-bezier function. Also handles the timingFunction property inside transition type object-values.

DTCG definition

/**
* Matches: token.type === 'cubicBezier' || token.type === 'transition'
* Returns:
*/
:root {
--var: cubic-bezier(0, 0, 0.5, 1);
}

Transforms strokeStyle type object-value token into a CSS string, using the CSS dashed fallback.

DTCG definition

/**
* Matches: token.type === 'strokeStyle'
* Returns:
*/
:root {
--var: dashed;
}

Transforms border type object-value token into a CSS string, using the CSS border shorthand notation.

DTCG definition

/**
* 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.


Transforms typography type object-value token into a CSS string, using the CSS font shorthand notation.

DTCG definition

/**
* Matches: token.type === 'typography'
* Returns:
*/
:root {
--var: italic 400 1.2rem/1.5 'Fira Sans', sans-serif;
}

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.

DTCG definition

/**
* Matches: token.type === 'transition'
* Returns:
*/
:root {
--var: 200ms ease-in-out 50ms;
}

Transforms shadow type object-value token (which can also be an array) into a CSS string, using the CSS shadow shorthand notation.

DTCG definition

/**
* 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.


Wraps the value in a CSS url() function

// Matches: token.type === 'asset'
// Returns:
url('https://www.example.com/style.css');

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=

Prepends the local file path

// Matches: token.type === 'asset'
// Returns:
'path/to/file/asset.png';

Wraps the value in a double-quoted string and prepends an ’@’ to make a string literal.

// Matches: token.type === 'asset'
// Returns: @"string"

Wraps the value in a double-quoted string to make a string literal.

// Matches: token.type === 'asset'
// Returns: "string"

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);

Wraps the value in a double-quoted string to make a string literal.

// Matches: token.type === 'content'
// Returns: "string"

Wraps the value in a double-quoted string to make a string literal.

// Matches: token.type === 'asset'
// Returns: "string"

Scales the number by 16 (or the value of basePxFontSize on the platform in your config) to get to points for Flutter

16.00
// Matches: token.type === 'dimension'