If you need to allow for variations in formatting, you can set a font style, draw text, measure it using measureText
, set a new style, and then draw the next block like this:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
// get canvas / context
var can = document.getElementById('my-canvas');
var ctx = can.getContext('2d')
// draw first text
var text = '99%';
ctx.font = 'bold 12pt Courier';
ctx.fillText(text, 50, 50);
// measure text
var textWidth = ctx.measureText(text).width;
// draw second text
ctx.font = 'normal 12pt Courier';
ctx.fillText(' invisible', 50 + textWidth, 50);
<!-- language: lang-html -->
<canvas id="my-canvas" width="250" height="150"></canvas>
<!-- end snippet -->
Further Reading