Overview
Converts a colors object to a CSS custom properties (CSS variables) string. This method transforms camelCase color keys into kebab-case CSS variable names with a configurable prefix.Signature
Parameters
The colors object containing color key-value pairs. Typically from
DynamicColor.colors() response (e.g., colors.light, colors.dark, or colors.dayNight).The prefix to use for CSS variable names. The method will append a hyphen and the kebab-cased color 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., onPrimary becomes on-primary).Example
With Custom Prefix
Implementation
The method iterates through all keys in the colors object and formats them as CSS variables:This method only generates the CSS string. To apply these variables to the DOM, use
colorsToDom() instead.Use Cases
- Generate CSS variables for manual insertion into stylesheets
- Preview CSS variable output before applying to DOM
- Export CSS variables to files or external style management systems
- Custom CSS variable integration workflows
See Also
colorsToDom()- Apply colors as CSS variables directly to the DOMpaletteToCssVars()- Convert palette object to CSS variablesDynamicColor.colors()- Get the colors object