Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createTokens

Design token registry with hierarchical collections, alias resolution, and namespace support.


AdvancedApr 5, 2026

Usage

The createTokens composable allows you to define a collection of design tokens, which can be primitive values or aliases that reference other tokens. It provides a context for resolving these tokens, making it easy to access design values throughout your application.

ts
import { createTokens } from '@vuetify/v0'

// Default behavior (depth = Infinity): fully flatten nested objects
const tokens = createTokens({
  color: {
    primary: '#3b82f6',
    secondary: '#64748b',
    info: '{primary}'
  },
  radius: {
    sm: '4px',
    md: '8px',
  },
})

tokens.resolve('color.primary') // '#3b82f6'
tokens.resolve('color.info') // '#3b82f6' (alias resolved)
tokens.resolve('radius.md') // '8px'

const features = createTokens({
  dark: true,
  rtl: { value: true, variation: 'toggle' },
}, { flat: true })

// With flat: true, nested objects are kept as-is at their base id
features.resolve('rtl') // { value: true, variation: 'toggle' }

Context / DI

Use createTokensContext to share a token registry across a component tree:

ts
import { createTokensContext } from '@vuetify/v0'

export const [useTokens, provideTokens, tokens] =
  createTokensContext({
    namespace: 'my:tokens',
    tokens: {
      colors: {
        primary: '#3b82f6',
        secondary: '{colors.primary}',  // alias
      },
    },
  })

// In parent component
provideTokens()

// In child component
const tokens = useTokens()
tokens.resolve('colors.primary')  // '#3b82f6'

Options

createTokens

OptionTypeDefaultNotes
flatbooleanfalseKeep nested objects as-is at their base key instead of flattening
prefixstringPrepend a string to every token ID on registration (e.g. 'color.')

createTokensContext

Accepts all createTokens options plus:

OptionTypeDefaultNotes
namespacestringDI namespace string (e.g. 'my:tokens')
tokensTokenCollectionInitial token collection registered when the context is created

Architecture

createTokens extends createRegistry and powers token-based systems:

Tokens Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Tokens Hierarchy

Reactivity

createTokens uses minimal reactivity like its parent createRegistry. Token resolution is cached but not reactive.

Tip

For reactive theming Use useTheme which builds on createTokens with proper reactivity for theme switching.

Examples

Design Token Explorer

A design system with four token categories — color palettes, semantic aliases, spacing, and radius — split across two files:

FileRole
tokens.tsDefines the token collection with nested color scales and semantic aliases
design-system.vueExplorer UI with category tabs, search, and an alias resolver

Key patterns:

  • Nested objects flatten to dot-notation IDs: color.blue.500, spacing.md

  • Alias syntax {color.blue.500} references other tokens — resolve() follows the chain

  • isAlias() distinguishes alias references from direct values

  • Click any token to resolve it in the Alias Resolver panel

39 tokens registered
Alias Resolver
alias #3b82f6

Frequently Asked Questions

API Reference

The following API details are for the createTokens composable.

Functions

createTokens

(tokens?: TokenCollection, options?: TokenOptions) => E

Creates a new token instance.

createTokensContext

(_options: TokenContextOptions) => ContextTrinity<E>

Creates a new token context.

useTokens

(namespace?: string) => E

Returns the current tokens instance.

flatten

(tokens: TokenCollection, prefix?: string, flat?: boolean) => FlatTokenCollection[]

Flattens a nested collection of tokens into a flat array of tokens. Each token is represented by an object containing its ID & value.

Benchmarks

Every operation is profiled across multiple dataset sizes to measure real-world throughput. Each benchmark is assigned a performance tier—good, fast, blazing, or slow—and groups are scored by averaging their individual results so you can spot bottlenecks at a glance. This transparency helps you make informed decisions about which patterns scale for your use case. Learn more in the benchmarks guide.

View benchmark source↗

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/