External palettes¶
An external palette stores named colors outside the card YAML so the same color system can be reused by many cards. A palette can also provide different values for Home Assistant light and dark mode while the card keeps using the same color names.
This page shows how to load a palette, how its JSON file is structured, and how to use its colors in the card.
Load a palette¶
Load a palette when named theme colors should be available throughout the card without repeating individual color values.
rainbow is the name used by the card. The second value is the path to the JSON file.
Palette loading and browser cache
A palette may take a moment to load the first time it is used or after a hard refresh. Palette-dependent colors appear as soon as the file becomes available.
Use a palette color¶
After loading the file, use its CSS variables like other colors:
Use different colors for light and dark mode¶
The palette file can map the same variable to different color references:
The card keeps using var(--fhs-sys-rainbow-red); the active mode chooses the actual color.
Create your own palette¶
A palette contains:
reffor the actual color values;modes.lightfor light-mode mappings;modes.darkfor dark-mode mappings.
Write the palette keys without the CSS -- prefix. For example, define fhs-sys-rainbow-red in the JSON and use it in card YAML as var(--fhs-sys-rainbow-red).
Keep variable names consistent so the same names can be used throughout your cards.
Use Material Design tonal colors¶
A palette can contain tonal values from dark to light, commonly named from 0 to 100. The light and dark mappings then choose a suitable tone without changing the variable used by the card.