Skip to content Skip to sidebar Skip to footer

Javascript: Is It Possible To Set Different Font Sizes For Different Texts In A 2d Canvas?

Afaik, you can only set the font for the WHOLE canvas. var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.font = '30px Arial' I would like l

Solution 1:

Yes, its is possible:

//first text
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
//second text
ctx.font = "20px Arial";
ctx.fillText("Bell World",50,100);

Post a Comment for "Javascript: Is It Possible To Set Different Font Sizes For Different Texts In A 2d Canvas?"