Skip to content

Instantly share code, notes, and snippets.

@thomasloven
Last active December 11, 2024 08:32
Show Gist options
  • Save thomasloven/97c2a441abff7e735b77bc4aff5f7c5e to your computer and use it in GitHub Desktop.
Save thomasloven/97c2a441abff7e735b77bc4aff5f7c5e to your computer and use it in GitHub Desktop.
Use custom fonts in Home Assistant
# /config/configuration.yaml
...
lovelace:
mode: yaml
resources:
- url: /local/myfont.css
type: css
...
frontend:
themes:
change_font:
paper-font-body1_-_font-family: myfont
<!--
/config/www/myfont.css
Also need /config/www/myfont.ttf
or whatever file format it is, could be several.
src: may need to be adjusted with a format() function or so - check the font docs.
-->
@font-face {
font-family: "myfont";
src: url("/local/myfont.ttf");
}
@devedsmith
Copy link

How is this not in the UI yet?

@MartinJohannesNilsen
Copy link

Commenting as I did not understood this myself in the beginning (HA rookie here). Remember that if you are using HACS, you should not define this part in your configuration.yaml:

lovelace:
  mode: yaml
  resources:
    - url: /local/myfont.css
      type: css

But rather add the resource in hacs (three dots in top right corner).

Then you can overwrite the html variable in your theme as this:

# /config/configuration.yaml

frontend:
  themes:
    my_custom_theme:
      # Font
      primary-font-family: "Newly imported font-family name"
      paper-font-common-base_-_font-family: "var(--primary-font-family)"            

Note that I used common-base instead of body1 as OP did

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment