Re: Can't understand how custom fonts work

Thanks @Jnix284 . @Jaycee_Lewis any help you can provide to move this over would be great so I don’t have to reproduce the thread. Thanks!

This poor comment was orphaned from its main thread. Here’s the link.

Hi @PPardi,

I’ll add the answer here

format("ttf")

is not recognized by the browser.

You should change it to

format("truetype")

Also - if you have additional formats like opentype, woff, woff2, svg you should also embed them to make the fonts displayed correctly in all type of browsers. You can find a list of which browser uses which format you [here](http://which%20browser uses which format you can find herehttps://css-tricks.com/snippets/css/using-font-face-in-css/#aa-deepest-possible-browser-support).

Furthermore: Since it’s a corporate font and you’re developing a specific theme for your company you don’t necessarily need to implement the font in the theme settings. For easier use I’d do it like this:

  • upload your font in the design-manager or the file manager
  • implement your font directly in the CSS with @font-face rules like you did it
  • define the font sizes, weights, styles, variations etc. directly in the CSS file
  • develop custom modules for headings and a rich-text which does not include the font settings so the user can’t change the font inside the rich-text. Here’s a ressource for modifying the rich-text field(only possible in CLI)

A custom Headline module is pretty simple. Just add a select option “headline size” and a simple text field “headline” to the module and write it like this:

<{{module.headline_size}}>{{module.headline}}</module.headline_size>

The values of the select should be: h1, h2, h3, h4… or just limit the options to what ever options you would like to give.

For the plain looks I recommend to add a “headline style” function like this

<{{module.headline_size}} class="{{ module.headline_style}}">{{module.headline}}</module.headline_size>

The only thing left to do is writing your CSS like

h1,.h1{
{# add H1 styling here #}
}

h2,.h2{
{# add H2 styling here #}
}

h3,.h3{
{# add H3 styling here #}
}

h4,.h4{
{# add H4 styling here #}
}

h5,.h5{
{# add H5 styling here #}
}

h6,.h6, small, .small{
{# add H6 styling here #}
}

I’ve created a GitHub file about custom font usage that should give you an idea how you can easily hardcode a font into a theme a while ago.

best,

Anton

Thanks @Anton I implemented the fonts per your guidance and things are behaving much more consistently now. Thanks so much for the help!