(Note: I'm still kind of a beginner) I have a custom font that works fine for nearly all text on my page, but I have a canvas element that I want text on so I try to apply the size and font by using
ctx.font = '20px myCustomFont'; ctx.fillText('Hello World', 150, 250);
it will resize to 20px but it only displays the default font. I am not sure what to do, here's the relevant code:
My CSS:
* {
font-family: 'myCustomFont';
}
@font-face {
font-family: 'myCustomFont';
src: url('myCustomFont.ttf');
My HTML:
<p>This uses the custom font perfectly fine</p>
<canvas id='canvas' width='800' height='400'></canvas>
My JavaScript:
let ctx = document.getElementById('canvas').getContext('2d');
ctx.font = "20px myCustomFont";
ctx.fillText('Hello World', 150, 250); //Hello World will be at 20px, but it wont use the custom font