mpmp
mpmp

Reputation: 2459

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 lets say, text1 to be "30px Arial" and text2 to be "10px Arial". Is this possible?

Upvotes: 1

Views: 2145

Answers (1)

Anderson Contreira
Anderson Contreira

Reputation: 798

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);

Upvotes: 8

Related Questions