Can't understand how custom fonts work

Hi all,

I need some help understanding how custom fonts work across the Hubspot development environment.

I’m attempting to use custom TTF fonts our company has purchased on Hubspot. They show up as expected but how to use them in Hubspot is inconsistent.

What I’ve done

1. I’ve tried following the instructions here: Use fonts in HubSpot and here: Add custom fonts to a theme (hubspot.com)

2. I’ve tried updating my themes font using the instructions here: Edit your theme settings (hubspot.com)

The problem I’m having

1. The fonts appear in some menus and not others. I can see them (sort of) in theme settings (per number 2 above) but changing settings don’t seem to make a difference.

2. The names of fonts and their varieties show up in different ways in different places. For example,

Here’s how they show up in the Rich Text Editor:

But here’s how they show up in the Theme editor and for individual controls like buttons:

Also in the theme editor, a font style shows up as the font name. I have no idea why.

I tried “resetting” everything by pulling out the custom fonts from theme.json but it appears to have made no difference (the fonts still show up and editing that file hasn’t impacted anything).

Here is my folder structure for my custom fonts. I’m not sure if it’s correct because the documentation is a little obscure.

I also added this code to my theme-override.css but I have no idea if it’s doing anything (I also tried changing the font-family on my h1 style to test but I’m not sure if it’s working).

Needless to say, I’m very confused how all this is supposed to work and because I can’t see impacts to changes I make, I can’t debug it. Any guidance would be appreciated.

Paul

Hi @PPardi it’s difficult to say why it is inconsistent without knowing how the theme you’re using is coded to handle fonts.

It looks like you have the fonts configured correctly to be used in the RTE, but if you want them to show in the theme settings, you would need to redefine the variable that’s used to control that setting.

For example, if you have a theme setting for Base Font, which has a variable of --ff-base, and you want to redefine the variable it would be like this:

:root {
--ff-base: Avenir, sans-serif !important;
}

all of this can be done via the child.css without having to create a fonts.json, unless it’s a theme you’ve developed and you are trying to define the fonts initiall - it is a little hard to tell whether you’re developing a theme or modifying an existing theme.

Thanks Jennifer. I used the process here to create a theme: Getting started with themes (hubspot.com). This is the theme that I created with this process in which I’m trying to use the fonts. How do I tell if I have a theme setting for a base font? In which file can I check that?

My goal is to add custom fonts to my environment and use them consistently everywhere. I’ve developed against a lot of platforms and in most cases, you add font files to the environment through an interface and they show up in all font lists and are available to all pages on the site. I’m not sure which process I’m supposed to use to do this (if its even supported) and why I’m seeing different representations of which fonts are available across the site.

For example, in the screen shot below, you’ll see different options for each font type and these appear to be coming from the font folders I set up (using the font.json to define the font). This dropdown appears in the theme settings for my H1 style. The issue is that when I choose one of these, the font isn’t applied to the style. If I set Brandon Grotesque to my H1 style and then choose H1 as the style in the RTE, it shows a different font.

@PPardi Since you’re developing your own theme and looking for help with code (not a marketing issue with websites), I would recommend posting this in the Developer discussion where you can get help with coding.

Maybe @Jaycee_Lewis can help with moving this thread for you? :slightly_smiling_face:

Thanks for the tag, @Jnix284. Working on getting this moved. — Jaycee

Hey, @PPardi :waving_hand: Thanks for your patience. @Stephanie-OG @Anton @Indra @Josh, do you have anything you can add to the strong work from @Jnix284?

Thank you for taking a look! — Jaycee

Hi @PPardi,

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