Easy Tutorial
❮ Att Th Axis Att Textarea Form ❯

HTML canvas measureText() Method

HTML canvas Reference Manual

Example

Check the width of the font before outputting text on the canvas:

JavaScript:


Browser Support

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.


Definition and Usage

The measureText() method returns an object that contains the width of the specified font in pixels.

Tip: Use this method if you need to know the width of the text before outputting it to the canvas.

| JavaScript Syntax: | context.measureText(text).width; | | --- | --- |

Parameter Values

Parameter Description
text The text to be measured.
❮ Att Th Axis Att Textarea Form ❯