Language PreviewDTL is currently in alpha. Explore the language, try the playground, and learn how to use it.Alpha release coming soon.

Functions

Functions allow you to create reusable logic for generating and transforming tokens. DTL includes built-in functions and supports user-defined functions.

Defining Functions

Define functions using the fn keyword:

Function Parameters

Functions can take multiple parameters with type annotations:

Using Functions

Call functions in token definitions:

Built-in Functions

palette()

Generate a color palette from a base color and scale values:

scale()

Generate a color scale with N steps:

responsive()

Define responsive values for different breakpoints:

Color Methods

Colors have built-in methods for transformations:

Size (Dimension) Methods

Size values support arithmetic operations and unit conversion:

Size Conversion Functions

Duration Methods

Duration values support arithmetic operations and unit conversion:

Duration Conversion Functions

Number Methods

Numbers support arithmetic operations and clamping:

FontWeight Methods

Font weights can be adjusted and converted:

FontWeight Conversion Function

FontFamily Methods

Font families can have fallback stacks added:

String Methods

Strings support various transformations:

Boolean Functions

Boolean values can be negated:

Function Scope

Functions are available throughout your file after they're defined:

Best Practices

  • Keep functions simple:Functions should do one thing well
  • Use descriptive names:Function names should clearly indicate their purpose
  • Document with comments:Add doc comments to explain function behavior
  • Reuse common patterns:Extract repeated calculations into functions