/

HTML / CSS / JavaScript Tutorial

JavaScript canvas2d object method: measureText()

[this page | pdf | back links]

The measureText() method of the JavaScript DOM object returned by the getContext("2d") method applied to the HTML <canvas> element returns an object indicating the width of the specified text. It can be used to measure the width of some text before it is written onto the canvas

 

The width can be found using the following syntax with the following parameters.

 

context.measureText(text).width

 

Parameter

Required / Optional

Description

text

Required

String specifying text

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile