Skip to content

How to use Material 3 themes

Once you have installed one of the Material 3 themes, you can use all the color definitions the theme offers in your Home Assistant (custom) cards.

To make full use of these theme color definitions, either the (custom) card itself should offer CSS styling functionality, or via a custom plugin that makes it possible to style parts of the card.

Start to use the Theme color definitions!

The key point in using all the features of the Home Assistant Material 3 themes is to use the theme color definitions whenever possible and appropriate. In that case, your card will follow the theme in both light and dark mode!

  # Note: below is from Swiss Army Knife tool "style" YAML section
  style:
    fill: var(--primary-text-color)           # Material text color
    stroke: var(--theme-sys-color-primary60)  # M3 theme system color
  # Note: below is from Swiss Army Knife tool "style" YAML section
  style:
    fill: red                                 # Hard coded red color
    stroke: #456712                           # Hard coded hex color

It can't get any easier 😄

Using theme definitions is not specific to the Material 3 themes: using them was already required for the light/dark themes to work

I will use Teal Blue example theme D06 to show how you can use a Material 3 theme. The card shown is example 12 from the Swiss Army Knife custom card.

AmoebeLabs Material 3 Theme Example D06 Light The light variant.


AmoebeLabs Material 3 Theme Example D06 Dark The dark variant.

How to use the standard material colors

The Material 3 themes map the color definitions to the standard Material Design color definitions Home Assistant is using. This means you can use the standard Material Design primary and secondary font and background colors as before to style your cards.

If fonts use the var(--primary-text-color) CSS variable, both light and dark themes should work out of the box!

For a list of used CSS variables by the Lovelace frontend of Home Assistant, look here

The above example uses these default font and background colors for the cards background and text parts.

How to define and use dedicated colors

In some cases you can't use the Theme colors, you need to use dedicated colors. Traffic light colors or the Airvisual colors are a good example of that use case.

You have 3 options to use dedicated colors in your cards:

  • Use hard coded colors (HEX, RGB, HSL, etc.)
  • Clone the theme you want to use, and define the colors in the theme, and use those custom color names in your cards.

    Say you define them as
    traffic-light-red: red
    traffic-light-yellow: yellow
    traffic-light-green: green
    
    You can use the colors in the card using the CSS variable var(--traffic-light-red)
  • If the card is made with the Swiss Army Knife custom card, you can define those colors in the user CSS definitions, and use them in your card as CSS variables.

The above example uses dedicated colors (green, yellow, orange, red, purple) for the AirVisual representation in the first wide card.

AirVisual color definitions for Swiss Army Knife segmented arc tool
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  segments:
    colorstops:
      gap: 0.1
      colors:
        0: '#A8E05F'    # Green
        51: '#FDD74B'   # Yellow
        101: '#FE9B57'
        151: '#FE6A69'
        201: '#A97ABC'
        301: '#A87383'
  styles:
    foreground:
      fill: darkgrey
    background:
      fill: var(--theme-sys-elevation-surface-neutral5)

How to use the Material 3 colors

The Material 3 themes define more colors: primary, secondary, tertiary and error reference and system color palettes and surface elevation colors.

All these colors can be used as CSS variables.

All Material 3 themes support light and dark mode. It does this by redefining the system colors with theme mode dependent reference colors.

If you use Material 3 color names in your cards, non Material 3 themes will show fallback colors (mostly black and white)

Material 3 System colors

The Material 3 system colors are dependent of the theme mode (light or dark). Use this colors if you want to adapt the color to the theme mode.

Light variant Dark variant
Example d06, Teal Blue Light: AmoebeLabs Material 3 Theme Example D06 Light Example d06, Teal Blue Dark: AmoebeLabs Material 3 Theme Example D06 Dark

System colors are used throughout this example:

  • The background of the circles use a surface system color: this color is darker than the background in a light theme, and lighter than the background in a dark theme.

    This surface color is also used in the half circle in the 'Hall' (4th) card, the circle around the icon in the 'Bedroom' (5th) card and the background of the first part of the "Poseidon" (7th) card.
  • The same is done for the actual value of the circles: these use the primary dark variants in the light theme, and the light variants in the dark theme.
  • The circles for battery and link quality use tertiary system colors.

Check the Theme colors page for these system colors you can use.

System color example 'Hall' (4th) card for Swiss Army Knife circle tool (half circle in first column)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  - toolset: color1
    position:
      cx: 0
      cy: 50
    tools:
      # ------------------------------------------------------------
      - type: circle
        position:
          cx: 50
          cy: 50
          radius: 50
        styles:
          circle:
            fill: var(--theme-sys-elevation-surface-neutral4)
            stroke: none
Hestia color definitions for first Swiss Army Knife segmented arc tool
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  segments:
    colorlist:
      gap: 1
      colors: &4-colors                       # Define YAML template
        - var(--theme-sys-palette-primary50)
        - var(--theme-sys-palette-primary45)
        - var(--theme-sys-palette-primary40)
        - var(--theme-sys-palette-primary35)
  styles:
    foreground:
      fill: darkgrey
    background:
      fill: var(--theme-sys-elevation-surface-neutral4)
      opacity: 1

Hestia color definitions re-using YAML template
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  segments:
    colorlist:
      gap: 1
      colors: *4-colors                     # Use YAML template
  styles:
    foreground:
      fill: darkgrey
    background:
      fill: var(--theme-sys-elevation-surface-neutral4)
      opacity: 1
System color battery example using tertiary foreground color and neutral background color
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  segments:
    colorlist:
      gap: 1
      colors:
        - var(--theme-sys-palette-tertiary45)
  styles:
    foreground:
      fill: darkgrey
    background:
      fill: var(--theme-sys-elevation-surface-neutral4)
      opacity: 1

Material 3 Reference colors

The Material 3 reference colors are independent of the theme mode (light or dark). Use this colors if you want to keep the same color.

Light variant Dark variant
Example D06, Teal Blue Light: AmoebeLabs Material 3 Theme Example D06 Light Example D06, Teal Blue Dark: AmoebeLabs Material 3 Theme Example D06 Dark

Reference colors are used only in the last card (hardly visible in the lower right of the image):

  • The segments of the circles use primary reference colors: you can see they remain the same for both the light and dark mode.

Check the Theme colors page for these 264 reference colors you can use.

Reference color example 'Illuminance' card for Swiss Army Knife segmented arc tool
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  segments:
    colorlist:
      gap: 1
      colors:
        - var(--theme-ref-palette-primary30)    # Primary ..
        - var(--theme-ref-palette-primary35)    # ..reference colors ..
        - var(--theme-ref-palette-primary40)    # ..from dark ..
        - var(--theme-ref-palette-primary45)    # ..(30% lightness) ..
        - var(--theme-ref-palette-primary50)
        - var(--theme-ref-palette-primary60)
        - var(--theme-ref-palette-primary65)
        - var(--theme-ref-palette-primary70)
        - var(--theme-ref-palette-primary75)    # ..to lighter color ..
        - var(--theme-ref-palette-primary80)    # ..(80% lightness)
  styles:
    foreground:
      fill: darkgrey
    background:
      fill: var(--theme-sys-elevation-surface-neutral4)
      opacity: 1
Back to top