Design Tokens Community Group (DTCG) Specification

repository·main·Indexed 24 days ago

https://github.com/design-tokens/community-group

Official specification and tools for standardizing design tokens, enabling the sharing of stylistic properties like color, spacing, and typography across platforms. Includes documentation on the @dtcg/schemas package for generating JSON schemas, technical reports on color terminology and types, and guidelines for contributing to the W3C-aligned standards.

Tokens
32.1K
Snippets
84
Records
153
Agent score
83%

What's inside Design Tokens Community Group

  1. Overview of the Design Tokens Community Group (DTCG)

    main

    The Design Tokens Community Group (DTCG) is the official body responsible for the design tokens specification. The group's goal is to provide standards that allow products and design tools to share stylistic pieces of a design system (such as colors, spacing, and typography scales) across many tools and platforms at scale.

    The specification is built on three core principles:

    1. Inclusive: Empowering people of all skill levels to participate and implement tools.
    2. Focused, yet extensible: Maintaining a small, simple footprint with zero dependencies while allowing for future extensibility.
    3. Stable: Providing a long-term foundation by using existing and trusted standards.
  2. Understand the Design Tokens Community Group (DTCG) mission

    main
    The DTCG provides standards for sharing stylistic pieces of a design system at scale. The goal is to enable products and design tools to rely on a common language for design tokens, such as sharing color palettes or themes between different tools and lowering the barrier for design and development teams to deploy tokens in their workflows.
  3. Bundle resolver documents by inlining files

    main

    Inlining is a bundling strategy where all reference objects ($ref) pointing to remote files are replaced with the actual contents of those files. This results in a single, portable JSON document.

    Pros and Cons:

    • Pro: Simplifies portability by reducing the document to a single file.
    • Con: Causes data duplication. If the same file is referenced multiple times (e.g., in both light and dark contexts), its entire content is copied into every instance, which can make the document difficult for humans to read.
    {
      "$schema": "https://www.designtokens.org/schemas/2025.10/resolver.json",
      "sets": {
        "foundation": {
          "sources": [
            {
              // (contents of foundation/colors.json)
            },
            {
              // (contents of foundation/size.json)
            }
          ]
        }
      }
    }
  4. Understand the relationship between JSON Schema and DTCG

    main

    While both use JSON syntax and support hierarchical structures, they serve different purposes:

    FeatureJSON SchemaDTCG
    Primary PurposeA generic tool for describing JSON structures.A specification for declaring and exchanging design tokens (colors, spacing, etc.).
    Data ExchangeNot intended for data exchange; used for validation.Designed to both declare schema and deliver actual token content.
    SemanticsGeneric JSON structure.Tailored specifically for design systems and design tokens.
    ReusabilitySupports $ref.Supports $ref and an additional {token.alias} syntax.

    Key takeaway: JSON is the syntax; DTCG is the semantics. DTCG defines how to use JSON to represent design tokens in a standardized, interoperable way.

  5. Detect Circular References in Tokens and Groups

    main

    Tools MUST implement circular reference detection and throw an error if a cycle is detected in any of the following:

    • Token aliases: {token} references.
    • Group extensions: $extends references.
    • JSON Pointer references: $ref properties.

    For $extends, tools SHOULD use the same algorithms used by JSON Schema validators for cycle detection. An error must be reported for all groups involved in the cycle.

    {
      "a": { "$extends": "{b}" },
      "b": { "$extends": "{c}" },
      "c": { "$extends": "{a}" }, // Creates circular reference: a → b → c → a
    }
  6. How array aliasing works in composite types

    main

    When a composite type contains an array, you can mix explicit values and token references. The following rules apply to array aliasing:

    1. Single value resolution: References in arrays always resolve to a single value of the appropriate type; they never cause the array to expand or flatten.
    2. No flattening: If you reference an entire array, that array is treated as a single element within the parent array.
    3. Type safety: Every element (whether explicit or a reference) must match the expected sub-value type for that composite type.
    4. Mixed composition: You can freely mix explicit values and references within the same array.
    {
      "$schema": "https://www.designtokens.org/schemas/2025.10/format.json",
      "layered-shadow": {
        "$type": "shadow",
        "$value": [
          "{base.shadow}",
          {
            "color": "{brand.accent}",
            "offsetX": { "value": 4, "unit": "px" },
            "offsetY": { "value": 4, "unit": "px" },
            "blur": { "value": 8, "unit": "px" },
            "spread": { "value": 0, "unit": "px" }
          }
        ]
      }
    }
  7. Understand the purpose of the Resolver format

    main
    The Resolver format provides a mechanism for managing design tokens that vary across different contexts (such as theming, sizing, or accessibility modes) without suffering from combinatorial explosion. Instead of storing every possible permutation of a token value for every context, this format allows you to deduplicate repeated values and explicitly enumerate the permutations of contexts, making storage and management more efficient.
  8. Understand Resolvers and Resolutions

    main

    A Resolver is a JSON document that extends the design tokens format to handle multiple contexts. It uses Modifiers (conditional sets of tokens) and Composition (the order in which tokens are combined) to produce different outputs.

    • Input: A JSON-serializable object passed to a resolver that specifies which context values to use (e.g., { "theme": "dark", "size": "mobile" }).
    • Resolution: A single possible permutation produced by a resolver for a specific input. For example, a resolver with a theme modifier (light/dark) and a size modifier (mobile/desktop) can produce 4 distinct resolutions: light-mobile, light-desktop, dark-mobile, and dark-desktop.
    • Resolver file: A JSON file with the .resolver.json extension containing the sets, modifiers, and composition rules.
    { "theme": "dark", "size": "mobile" }
  9. Understand Alias tokens

    main

    An Alias is a token value that references another token instead of a raw value. This allows you to create semantic layers (e.g., color.text.base) that point to primitive values (e.g., color.palette.black), making it easier to update themes or palettes globally.

    In the JSON format, an alias is defined using the "$value" key with a string reference in curly braces.

    {
      "$schema": "https://www.designtokens.org/schemas/2025.10/format.json",
      "color": {
        "palette": {
          "black": {
            "$type": "color",
            "$value": {
              "colorSpace": "srgb",
              "components": [0, 0, 0],
              "hex": "#000000"
            }
          }
        },
        "text": {
          "base": {
            "$value": "{color.palette.black}"
          }
        }
      }
    }
  10. Understand the design token resolution lifecycle

    main

    To produce correct output, tools must process resolution in four specific, sequential stages:

    1. Input validation: Verifying that the provided inputs match the declared modifiers and their allowed values.
    2. Ordering: Tracing the resolutionOrder array to flatten sets and modifiers into a single tokens structure.
    3. Aliases: Resolving token aliases (references) within the flattened structure.
    4. Resolution: The final resulting tokens structure.

    Note that aliases must not be resolved until after the ordering stage is complete.

  11. Implement Chained References

    main

    Tokens may reference other aliases, creating a chain. Tools must follow each reference in the chain until they reach a token with an explicit $value. This allows for multi-layered semantic mapping (e.g., linkbrandprimarybase_color).

    {
      "base": {
        "primary": {
          "$value": {
            "colorSpace": "srgb",
            "components": [0, 0.4, 0.8],
            "hex": "#0066cc"
          },
          "$type": "color"
        }
      },
      "semantic": {
        "brand": {
          "$value": "{base.primary}"
        },
        "link": {
          "$value": "{semantic.brand}"
        }
      }
    }