Overview
TheDesignSystem object is the core interface for working with Tailwind’s utilities, variants, and theme. It provides methods for parsing candidates, generating CSS, and managing the design system configuration.
Creating a Design System
Design systems are typically created internally during compilation, but you can create one manually:Properties
theme
Theme
The theme instance containing all CSS custom properties and their values.
utilities
Utilities
The utilities registry for registering and managing utility classes.
variants
Variants
The variants registry for managing variant modifiers like
hover:, md:, etc.invalidCandidates
Set<string>
Set of candidate strings that have been determined to be invalid. Used for caching validation results.
important
boolean
Whether utility declarations should be marked as
!important. Defaults to false.storage
Record<symbol, unknown>
General purpose storage for plugins and extensions. Each key must be a unique symbol to avoid collisions.
Parsing Methods
parseCandidate()
Parse a candidate string into structured candidate objects.string
required
The candidate string to parse (e.g.,
'hover:bg-blue-500', 'md:flex').'text-red-500/50' creates candidates for both color and opacity).
parseVariant()
Parse a variant string into a variant object.string
required
The variant string to parse (e.g.,
'hover', 'md', 'dark').null if the variant is invalid.
compileAstNodes()
Compile a parsed candidate into AST nodes.Candidate
required
The parsed candidate object to compile.
CompileAstFlags
Compilation flags:
CompileAstFlags.None- No special flagsCompileAstFlags.RespectImportant- Apply!importantifdesignSystem.importantis true (default)
String Conversion Methods
printCandidate()
Convert a parsed candidate back to its string representation.printVariant()
Convert a parsed variant back to its string representation.Ordering Methods
getClassOrder()
Get the sort order for an array of class names.string[]
required
Array of class names to get sort order for.
null if invalid).
getVariantOrder()
Get a map of variants to their sort order.IntelliSense Methods
getClassList()
Get a list of all available utility classes for IntelliSense.getVariants()
Get a list of all available variants for IntelliSense.candidatesToCss()
Convert an array of candidates to their CSS output.string[]
required
Array of class names to convert to CSS.
null for invalid classes) corresponding to each input class.
candidatesToAst()
Convert an array of candidates to AST nodes.string[]
required
Array of class names to convert to AST.
Theme Methods
resolveThemeValue()
Resolve a theme path to its CSS value.string
required
Theme path to resolve (e.g.,
'--color-blue-500', '--spacing-4').Can include an opacity modifier using / syntax: '--color-blue-500 / 50%'boolean
If
true, forces the value to be inlined rather than using a CSS variable reference. Defaults to true.undefined if the path doesn’t exist.
trackUsedVariables()
Track CSS variables used in arbitrary values to ensure they’re included in the output.string
required
Raw string that may contain CSS variable references.
canonicalizeCandidates()
Canonicalize an array of candidates by parsing and re-printing them.string[]
required
Array of candidate strings to canonicalize.
CanonicalizeOptions
Options for canonicalization.