+ 1
Canvas text?
How can i put text on a canvas
1 Answer
+ 1
You can use the `strokeText` and `fillText` methods of a `2DCanvasRenderingContext`.
For example:
```
// assuming thereâs a canvas in the DOM with the id âcanvasâ
const canvas = document.getElementById(âcanvasâ);
const ctx = canvas.getContext(â2dâ);
ctx.fillStyle = âwhiteâ; // #ffffff
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = âblackâ; // #000000
ctx.font = â20px Times New Romanâ;
ctx.fillText(âHello world!â, 10, 10);
ctx.strokeText(âHello world!â, 10, 30);
```