diff --git a/docs/user-guide/design-systems/design-tokens.njk b/docs/user-guide/design-systems/design-tokens.njk index 15373b1241..878cfb4230 100644 --- a/docs/user-guide/design-systems/design-tokens.njk +++ b/docs/user-guide/design-systems/design-tokens.njk @@ -42,20 +42,74 @@ desc: Learn how to create, manage and apply Penpot Design Tokens using W3C DTCG

If the value of the referenced token changes, this will also change the value of the tokens where it is referenced.

References to existing tokens are case sensitive.

-

Using equations

-

Token types with numerical values also accept mathematical equations. If, for example, you create a spacing.small token with the value of 2, and you then want to create a spacing.medium token that is twice as large, you could do so by writing {spacing.small} * 2 in its value. As a result, spacing.medium would have a value of 4.

-

Say you have a spacing.scale token with a value of 2. You could also use this token in the equation to calculate the value of spacing.medium by writing {spacing.small} * {spacing.scale} in its value.

+

Using math in token values

+

Token types with numerical values accept mathematical equations to calculate their values. This allows you to create dynamic relationships between tokens and build flexible design systems.

+

For example, if you create a spacing.small token with the value of 2, and you want to create a spacing.medium token that is twice as large, you can write {spacing.small} * 2 in its value. As a result, spacing.medium would have a value of 4.

+

You can also reference other tokens in your equations. Say you have a spacing.scale token with a value of 2. You could use this token in the equation to calculate the value of spacing.medium by writing {spacing.small} * {spacing.scale} in its value.

Tokens math
-

Mathematical equations can be performed using:

+ +

Basic operators

+

Mathematical equations can be performed using these basic operators:

+

Math functions

+

In addition to basic operators, you can use various math functions in your token values:

+ + +

Syntax and best practices

+

When writing math equations in token values, keep these guidelines in mind:

+ + +

Practical examples

+

Here are some common use cases for math in token values:

+ +

Round to the nearest whole number

+

When using multipliers that result in decimals, you can use the round() function to get whole numbers. For example, if sizing.sm has a value of 2:

+
round({sizing.sm} * 1.33)
+

This calculates 2 * 1.33 = 2.66, which rounds to 3.

+ +

Create a percentage from a unitless number

+

You can convert unitless numbers to percentages. For example, a Number token called lineHeights.heading.relaxed with a value of 1.5 can be written in a Line Height token as:

+
{lineHeights.heading.relaxed} * 100%
+

This calculates a resolved value of 150%.

+ +

Calculate maximum or minimum values

+

Use max() or min() to ensure values stay within bounds. For example:

+
max({spacing.base}, 8)
+

This ensures the spacing is at least 8, even if the base token is smaller.

+

Editing a token

Tokens can be edited by right-clicking the token and selecting Edit token. This will allow you to change the tokens name, value and description. Once the changes are made, click Save.