This document describes the technical specification for a file format to exchange design tokens between different tools.
This specification was published by the Design Tokens Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.
This is a snapshot of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C or the Design Tokens Community Group Membership. Don’t cite this document other than as work in progress.
This document has been published to facilitate Wide Review.
This document was produced by the Design Tokens Community Group, and contributions to this draft are governed by Community Contributor License Agreement (CLA), as specified by the W3C Community Group Process.
GitHub Issues are preferred for discussion of this specification.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY, MUST, MUST NOT, SHOULD, and SHOULD NOT in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
This section is non normative
Design tokens are a methodology for expressing design decisions in a platform-agnostic way so that they can be shared across different disciplines, tools, and technologies. They help establish a common vocabulary across organisations.
There is a growing ecosystem of tools for design system maintainers and consumers that incorporate design token functionality, or would benefit from doing so:
It is often desirable for design system teams to integrate such tools together, so that design token data can flow between design and development tools. For example:
While many tools now offer APIs to access design tokens or the ability to export design tokens as a file, these are all tool-specific. The burden is therefore on design system teams to create and maintain their own, bespoke "glue" code or workflows. Furthermore, if teams want to migrate to different tools, they will need to update those integrations.
This specification aims to facilitate better interoperability between tools and thus lower the work design system teams need to do to integrate them by defining a standard file format for expressing design token data.
These definitions are focused on the technical aspects of the specification, aimed at implementers such as design tools vendors. Definitions for designers and developers are available at designtokens.org.
Information associated with a name, at minimum a name/value pair.
Few examples:
color-text-primary: #000000;
font-size-heading-level-1: 44px;
The name may be associated with additional Token Properties.
Information associated with a token name.
For example:
Visual design creation and editing tools.
This includes:
Token translation tools are tools that translate token data from one format to another.
Few examples:
A token’s type is a predefined categorization applied to the token’s value.
For example:
Token tools can use Types to infer the purpose of a token.
For example:
Sets of tokens belonging to a specific category. For example:
Groups are arbitrary and tools SHOULD NOT use them to infer the type or purpose of design tokens.
A design token’s value can be a reference to another token. The same value can have multiple names or aliases.
The following Sass example illustrates this concept:
$color-palette-black: #000000;
$color-text-primary: $color-palette-black;
The value of $color-text-primary
is #000000
, because $color-text-primary
references $color-palette-black
. We can also say $color-text-primary
is an alias for $color-palette-black.
A design token whose value is made up of multiple, named child values. Composite tokens are useful for closely related style properties that are always applied together. For example, a typography style might be made up of a font name, font size, line height, and color.
Design token files are JSON (https://www.json.org/) files that adhere to the structure described in this specification.
JSON was chosen as an interchange format on the basis of:
When serving design token files via HTTP / HTTPS or in any other scenario where a media type (formerly known as MIME type) needs to be specified, the following MIME type should be used for design token files:
application/design-tokens+json
However, since every design token file is a valid JSON file and it may not always be possible to configure web servers as needed, it is also acceptable to use the plain JSON media type: application/json
. The above, more specific media type is preferred and should be used wherever possible.
Tools that can open design token files MUST support both media types.
When saving design token files on a local file system, it can be useful to have a distinct file extension as this makes them easier to spot in file browsers. It may also help to associate a file icon and a preferred application for opening those files. The following file extensions are recommended by this spec:
.tokens
.tokens.json
The former is more succinct. However, until this format is widely adopted and supported, the latter might be useful to make design token files open in users’ preferred JSON editors.
Tools that can open design token files MAY filter available files (e.g. in an open file dialog) to only show ones using those extensions. It is recommended that also provide users with a way of opening files that do not use those extensions (e.g. a “show all files” option or similar).
Tools that can save design token files SHOULD append one of the recommended file extensions to the filename when saving.
The group is currently exploring the addition of a JSON Schema to support the spec.
A concern about file size limitations of JSON files was raised by one of the vendors. The working group continues to gather feedback about any limitations the JSON format imposes.
An object with a “value” property is a token. Thus, “value” is a reserved word in our spec, meaning you can’t have a token whose name is “value”. The parent object’s key is the token name.
The example above therefore defines 1 design token with the following properties:
Name and value are both required.
Token values may be any valid JSON type:
string
number
array
object
boolean
null
Additionally, tokens may be defined with a more specific Token Type
The structure in the example above is a JSON object, an unordered set of name/value pairs.
Please raise concerns if these limitations create problems for implementers.
While “value” is the only required property for a token, a number of additional properties may be added:
A plain text description explaining the token’s purpose. Tools MAY use the description in various ways. For example:
The description property must be a plain JSON string, for example:
Declares the type of the token. See “Types” for more information.
The extensions property is an object where tools MAY add proprietary, user-, team- or vendor-specific data to a design token. When doing so, each tool MUST use a vendor-specific key whose value may be any valid JSON data.
In order to maintain interoperability between tools that support this format, teams and tools should restrict their usage of extension data to optional meta-data that is not crucial to understanding that token’s value.
Tool vendors are encouraged to publicly share specifications of their extension data wherever possible. That way other tools can add support for them without needing to reverse engineer the extension data. Popular extensions may also be incorporated as standardized features in future revisions of this specification.
The extensions section is not limited to vendors. All token users can add additional data in this section for their own purposes.
A file may contain many tokens and they may be nested arbitrarily in groups like so:
The names of the groups leading to a given token (including that token’s name) are that token’s path, which is a computed property. It is not specified in the file, but parsers that conform to this spec must be able to expose the path of a token. The above example, therefore, defines 4 design tokens with the following properties:
Because groupings are arbitrary, tools MUST NOT use them to infer the type or purpose of design tokens.
The format editors acknowledge existing best-practices for token naming, but place no direct constraints on naming via the specification.
Groups may include an optional description property. For example:
Suggested ways tools may use this property are:
Groups may support additional properties like type and description. Should other properties be supported at the group level?
Tools that let users pick or edit tokens via a GUI may use the grouping structure to display a suitable form of progressive disclosure, such as a collapsible tree view.
Token names are not guaranteed to be unique within the same file. The same name can be used in different groups. Also, export tools may need to export design tokens in a uniquely identifiable way, such as variables in code. Export tools should therefore use design tokens' paths as these are unique within a file.
For example, a translation tool like Style Dictionary might use the following design token file:
...and output it as Sass variables like so by concatenating the path to create variable names:
Instead of having explicit values, tokens can reference the value of another token. To put it another way, a token can be an alias for another token. This spec considers the terms "alias" and "reference" to be synonyms and uses them interchangeably.
Aliases are useful for:
For a design token to reference another, its value should be a string containing the period-separated (.) path to the token it’s referencing enclosed in curly brackets. For example:
When a tool needs the actual value of a token it must resolve the reference - i.e. lookup the token being referenced and fetch its value. In the above example, the "alias name" token’s value would resolve to 1234 because it references the token whose path is {group name.token name}
which has the value 1234.
Tools should preserve references and therefore only resolve them whenever the actual value needs to be retrieved. For instance, in a design tool, changes to the value of a token being referenced by aliases should be reflected wherever those aliases are being used.
Aliases may reference other aliases. In this case, tools should follow each reference until they find a token with an explicit value. Circular references are not allowed. If a design token file contains circular references, then the value of all tokens in that chain is unknown and an appropriate error or warning message should be displayed to the user.
The format editors are currently researching JSON Pointer syntax to inform the exact syntax for aliases in tokens. https://datatracker.ietf.org/doc/html/rfc6901#section-5
Many tools need to know what kind of value a given token represents in order to process it sensibly. Export tools may need to convert or format tokens differently depending on their type. Design tools may present the user with different kinds of input when editing tokens of a certain type (such as color picker, slider, text input, etc.). Style guide generators may use different kinds of previews for different types of tokens. Since design token files are JSON files, all the basic JSON types are available:
Additionally, this spec defines a number of more design-focused types. To set a token to one of these types, it MUST have a type property specifying the chosen type. Furthermore, that token’s value must then follow rules and syntax for the chosen type as defined by this spec.
If the type
property is absent, tools MUST treat values as one of the basic JSON types and not attempt to infer any other type from the value.
If a type
is set, but the value does not match the expected syntax then that token is invalid and an appropriate error should be displayed to the user. To put it another way, the type property is a declaration of what kind of values are permissible for the token. (This is similar to typing in programming languages like Java or TypeScript, where a value not compatible with the declared type causes a compilation error).
Represents a 24bit RGB or 24+8bit RGBA color in the sRGB color space. The type property must be set to the string “color”. The value must be a string containing a hex triplet/quartet including the preceding # character. To support other color spaces, such as HSL, export tools should convert color tokens to the equivalent value as needed.
For example, initially the color tokens may be defined as such:
Then, the output from a tool’s conversion to HSL(A) may look something like:
Represents an amount of distance in a single dimension in the UI, such as a position, width, height, radius, or thickness. The type property must be set to the string “dimension”. The value must be a string containing a number (either integer or floating-point) followed by either a “px” or “rem” unit (future spec iterations may add support for additional units). For example:
The “px” and “rem” units are to be interpreted the same way they are in CSS:
A naive approach like the one below may be appropriate for the first stage of the specification, but this may be more complicated than it seems due to platform/OS/browser restrictions.
Represents a font name or an array of font names (ordered from most to least preferred). The type property must be set to the string “font”. The value must either be a string value containing a single font name or an array of strings, each being a single font name. For example:
Represents the length of time in milliseconds an animation or animation cycle takes to complete, such as 200 milliseconds. The type property must be set to the string “duration”. The value must be a string containing a number (either integer or floating-point) followed by an “ms” unit. A millisecond is a unit of time equal to one thousandth of a second. For example:
Represents how the value of an animated property progresses towards completion over the duration of an animation, effectively creating visual effects such as acceleration, deceleration, and bounce. The type property must be set to the string “cubic-bezier”. The value must be an array containing four numbers. These numbers represent two points (P1, P2) with one x coordinate and one y coordinate each [P1x, P1y, P2x, P2y]. The y coordinates of P1 and P2 can be any real number in the range [-∞, ∞], but the x coordinates are restricted to the range [0, 1]. For example:
If so, which composites should be included initially?
The types described in the previous chapter are all for singular values (a color, a dimension, etc.). However, it can often be useful to group related values as a single token so that they can be used or referenced as a single unit. A typical example of this is a “typography style” as found in many design tools, which is a combination of the font name, weight, style, and color.
Other examples might be:
At first glance, groups and composite types might look very similar. However, they are intended to solve different problems and therefore have some important differences:
Just as with “normal” types for tokens, using a custom, composite type will allow tools to check that the values you use match the expected type. In our color pair example above, attempting to do the following would be invalid and tools should ignore the token and show an error to the user, since “Comic Sans MS” is not a valid color value.
Likewise, IDEs can offer appropriate auto-completions to users that manually author design token files.
Since composite types are user-defined, tools cannot provide specialized handling of them since they have no advanced knowledge of the type declarations. Here are some suggested strategies to get the most value out of user-defined composite types:
Given that composite types are ultimately composed of the core design token types, tools that encounter unfamiliar composite tokens could fall back to treating their individual values as separate tokens. In effect, the composite token would be treated the same way as a group of tokens.
Using the color pair type as an example, an export tool like Style Dictionary could just export 2 color variables for it. A token file like this…
… might be exported to Sass like this:
In a similar vein, a GUI tool can "pluck" out the individual values of a composite token and use them as it would normally.
E.g. a design tool like Figma might not have the concept of a color pair, so it can't do anything special with tokens of that type. However, that doesn't prevent it from displaying the foreground and background colors of those tokens alongside any plain color tokens in a color picker.
A tool might not understand certain user-defined type definitions in a token file and therefore can't do anything special with them. However, that tool could export or modify token files by adding their own type definitions.
For example, imagine Sketch wanted to export all layer styles from a Sketch document to a token file. The Sketch app could have a built-in type definition that corresponds to layer styles. Perhaps something like this:
It could then save out that type definition into the token file it exports. Other tools could then make use of that same type definition and do useful things with tokens of that type.
Via configuration files or settings menus, tools could let users define custom behavior for types they have defined. For instance, in an export tool like Style Dictionary, users might be able to configure a custom transform or formatter for their composite types. Then, this example...
...could be configured to export, for example, a mixin instead of 2 variables:
The downside is of course that teams need to set up and maintain these configurations themselves.
Since composite types are ultimately composed of the core design token types, a design tool could automatically display an appropriate UI for creating, editing, or previewing them.
For instance, the color pair example above consists of 2 colors, one with the key foreground
and the other with the key background
. A design tool could therefore display two color picker widgets using those keys as the respective labels.