Changing color for fillText() on HTML5

you have to set the color for the text.

Something like this:

const canvasObj = document.getElementById('canvas')
const context = canvasObj.getContext('2d')

context.font = "bold 24px verdana, sans-serif ";
var welcomeMessage = "Welcome to the store!";
context.textAlign = "start";
context.textBaseline = "bottom";
context.fillStyle = "#ff0000"; //<======= here
context.fillText(welcomeMessage, 10, 50);

context.font = "bold 14px verdana, sans-serif";
var message2 = "Your favorite store for videos games and latest DVDs!";
context.textAlign = "start";
context.textBaseline = "bottom";
context.fillStyle = "#00ff00"; //<======= and here
context.fillText(message2, 10, 100);
<canvas id="canvas" width="400" height="100"></canvas>

Also, it could be a good idea to name your context variable “context” or “cxt” instead of “canvas”. It would be less confusing 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)