Check the width of the text, before writing it on the canvas:
JavaScript:
![]()
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the measureText() method.
Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.
The measureText() method returns an object that contains the width of the specified text, in pixels.
Tip: Use this method if you need to know the width of a text, before writing it on the canvas.
| JavaScript syntax: | context.measureText(text).width; |
|---|
| Parameter | Description | Play it |
|---|---|---|
| text | The text to be measured | Play it » |
HTML Canvas Reference
Your message has been sent to W3Schools.