How can I write text on a HTML5 canvas element?

Budda picture Budda · Sep 13, 2010 · Viewed 183k times · Source

Is it possible to write text on HTML5 canvas?

Answer

Zibri picture Zibri · Apr 26, 2012

var canvas = document.getElementById("my-canvas");
var context = canvas.getContext("2d");

context.fillStyle = "blue";
context.font = "bold 16px Arial";
context.fillText("Zibri", (canvas.width / 2) - 17, (canvas.height / 2) + 8);
#my-canvas {
  background: #FF0;
}
<canvas id="my-canvas" width="200" height="120"></canvas>