Overview
Converts a palette object to a CSS custom properties (CSS variables) string. This method is specifically designed for Material Design 3 reference palette colors, which include tonal values from 0-100 for each color group (primary, secondary, tertiary, neutral, error).Signature
Parameters
The palette object containing palette color key-value pairs. Typically from
DynamicColor.palette() response (colors.palette).The prefix to use for CSS variable names. The method will append a hyphen and the kebab-cased palette key name.
Returns
A string containing CSS custom property declarations, one per line, formatted as
prefix-key-name: value;\nCamelCase keys are automatically converted to kebab-case (e.g., neutralVariant95 becomes neutral-variant95).Example
With Custom Prefix
Implementation
This method is a wrapper aroundcolorsToCssVars() with a different default prefix:
colorsToCssVars():
This method only generates the CSS string. To apply these palette variables to the DOM, use
paletteToDom() instead.Use Cases
- Generate Material Design 3 reference palette CSS variables
- Access full tonal scale for custom color derivations
- Create theme systems with granular palette control
- Export palette variables to external style systems
Material Design 3 Palette Structure
The palette includes tonal values (0-100) for:- Primary colors: Brand and key UI elements
- Secondary colors: Less prominent components
- Tertiary colors: Accents and highlights
- Neutral colors: Surfaces and backgrounds
- Neutral Variant colors: Alternative surface colors
- Error colors: Error states and warnings
See Also
paletteToDom()- Apply palette as CSS variables directly to the DOMcolorsToCssVars()- Convert colors object to CSS variablesDynamicColor.palette()- Get the palette object