strokeText method

The strokeText method draws a text outline on the canvas. The first parameter takes the text to be drawn, and the second and third parameters are the coordinates of this text on the canvas. The font size and type are set using the font property.

Syntax

javascriptcontext.strokeRect(text, x, y);

Example

Let's draw a text stroke with strokeRect, size of 30px and Arial type:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.font = '30px Arial';
ctx.strokeText('Hello world', 30, 50);

Результат:

See also

  • the fillText method
    that draws a plain text
  • the font property
    that sets the font size and type