# Custom fonts for HTML elements?

**URL:** <https://forum.playcanvas.com/t/custom-fonts-for-html-elements/40389>\
**Category:** Help & Support\
**Tags:** ui, html\
**Created:** [July 21, 2025, 4:15am UTC](https://forum.playcanvas.com/t/custom-fonts-for-html-elements/40389 "2025-07-21T04:15:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lifeofpain](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/lifeofpain/32/36732_2.png) [@lifeofpain](https://forum.playcanvas.com/u/lifeofpain)\
**Post date:** [July 21, 2025, 4:15am UTC](https://forum.playcanvas.com/t/custom-fonts-for-html-elements/40389/1 "2025-07-21T04:15:40Z")

</div>

Hi! I am currently working on a project that requires the use of overlaid HTML elements for text input. For stylistic reasons, I would like to use a custom font that isn’t hosted on any websites. Unfortunately however, I cannot get the URL of the source font asset inorder to use it in my CSS, and when I try the URL of the regular font asset, it doesn’t render the font. Any assistance would be appreciated.

---

<div class="post-metadata">

**Author:** ![M\_Danish](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/m_danish/32/31020_2.png) [@M\_Danish](https://forum.playcanvas.com/u/M_Danish)\
**Post date:** [July 25, 2025, 3:06am UTC](https://forum.playcanvas.com/t/custom-fonts-for-html-elements/40389/2 "2025-07-25T03:06:49Z")

</div>

Hey @lifeofpain! 👋

I’ve dealt with a similar issue when working with HTML UI over WebGL content. If your font isn’t hosted online and you’re using PlayCanvas assets, you can load the font dynamically using a Blob URL. Here’s a quick way to do it:

Upload your .ttf or .woff font file as an asset in PlayCanvas.

In your script, get the font asset file and convert it into a blob URL like this:

```javascript
const fontAsset = app.assets.find('YourFontFile.ttf');
const fontUrl = URL.createObjectURL(fontAsset.resource);

const style = document.createElement('style');
style.innerHTML = `
  @font-face {
    font-family: 'CustomFont';
    src: url(${fontUrl});
  }

  .custom-font {
    font-family: 'CustomFont', sans-serif;
  }
`;
document.head.appendChild(style);

```

document.head.appendChild(style);  
Then just apply the class custom-font to your HTML elements. This should render your custom font correctly even if it’s not hosted externally.

Hope this helps! Let me know if you run into any trouble setting it up. 👍

---

<div class="post-metadata">

**Author:** ![lifeofpain](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/lifeofpain/32/36732_2.png) [@lifeofpain](https://forum.playcanvas.com/u/lifeofpain)\
**Post date:** [July 26, 2025, 3:30am UTC](https://forum.playcanvas.com/t/custom-fonts-for-html-elements/40389/3 "2025-07-26T03:30:44Z")

</div>

Thank you so very much, I was struggling a lot with this.

---

<div class="post-metadata">

**Author:** ![Ramon](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@Ramon](https://forum.playcanvas.com/u/Ramon)\
**Post date:** [October 27, 2025, 11:37am UTC](https://forum.playcanvas.com/t/custom-fonts-for-html-elements/40389/4 "2025-10-27T11:37:09Z")

</div>

> [@M\_Danish](#):
>
> `const fontUrl = URL.createObjectURL(fontAsset.resource);`

Hi @M_Danish,  
This results in an error when I try it.

```javascript
TypeError: URL.createObjectURL: Argument 1 could not be converted to any of: Blob, MediaSource

```

How did you work around this?
