# Loading fonts in Phaser 3 not working

**URL:** <https://phaser.discourse.group/t/loading-fonts-in-phaser-3-not-working/8898>\
**Category:** Phaser 3\
**Created:** [February 15, 2021, 10:39am UTC](https://phaser.discourse.group/t/loading-fonts-in-phaser-3-not-working/8898 "2021-02-15T10:39:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![slushie0](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/slushie0/32/4823_2.png) [@slushie0](https://phaser.discourse.group/u/slushie0)\
**Post date:** [February 15, 2021, 10:39am UTC](https://phaser.discourse.group/t/loading-fonts-in-phaser-3-not-working/8898/1 "2021-02-15T10:39:07Z")

</div>

I’m trying to load my font (Dogica Pixel) into my game. I have a .ttf file at the path shown, but whenever I start the game, it just draws the text with the Times New Roman font (default).  
Here is my index.html:  
`

 Phaser Game

```
<style media='screen' type='text/css'>
    @font-face {
        font-family: 'dogica';
        src: url('assets/dogica/dogicapixel.ttf');
        font-weight: 400;
        font-weight: normal;
    }
    .fontPreload {
	  	font-family: 'Tangerine';
	  	position:absolute;
	  	left:-100px;
	}
</style>

```

Dogica
 `

And my game.js:  
var config = {  
type: Phaser.AUTO,  
width: 800,  
height: 600,  
scene: {  
preload: preload,  
create: create  
}  
};

var game = new Phaser.Game(config);

function preload () {}

function create () {  
this.add.text(200, 100, ‘Snekrun!’, {fontFamily: ‘dogica’});  
}

Any help?

---

<div class="post-metadata">

**Author:** ![theNeedle](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/theneedle/32/745_2.png) [@theNeedle](https://phaser.discourse.group/u/theNeedle)\
**Post date:** [February 15, 2021, 12:01pm UTC](https://phaser.discourse.group/t/loading-fonts-in-phaser-3-not-working/8898/2 "2021-02-15T12:01:31Z")

</div>

Refer to [this article](https://hacks.mozilla.org/2016/06/webfont-preloading-for-html5-games/) for more info on web font preloading in HTML5 games.

Check this examples ([example 1](https://phaser.io/examples/v3/view/game-objects/text/google-webfont), [example 2](https://phaser.io/examples/v3/view/game-objects/text/custom-webfont)) and [this rex note/plugin](https://rexrainbow.github.io/phaser3-rex-notes/docs/site/webfontloader/).

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [February 15, 2021, 7:19pm UTC](https://phaser.discourse.group/t/loading-fonts-in-phaser-3-not-working/8898/3 "2021-02-15T19:19:22Z")

</div>

Probably best to use something like [webfontloader](https://github.com/typekit/webfontloader), as in [game-objects/text/custom-webfont](https://phaser.io/examples/v3/view/game-objects/text/custom-webfont).

---

<div class="post-metadata">

**Author:** ![basstabs](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/basstabs/32/3639_2.png) [@basstabs](https://phaser.discourse.group/u/basstabs)\
**Post date:** [February 16, 2021, 8:53am UTC](https://phaser.discourse.group/t/loading-fonts-in-phaser-3-not-working/8898/4 "2021-02-16T08:53:21Z")

</div>

I had the same issue, but I found a workaround that didn’t require loading the fonts explicitly in Javascript. For my fonts to work, I had to take the additional step of adding an invisible element to my html that uses the custom font, i.e. something like:

```
<div style="font-family: dogica; visibility: hidden">
    .
</div>

```

I picked this up from a tutorial somewhere, but for the life of me I don’t remember where or I would link it. Basically from what I understand, css fonts aren’t explicitly loaded until they’re actually needed or something like that.
