TextMetrics.width

The readonly TextMetrics.width property contains the text's advance width (the width of that inline box) in CSS pixels.

SyntaxEdit

readonly metrics.width;

ExamplesEdit

Given this <canvas> element:

<canvas id="canvas"></canvas>

You can get a TextMetrics object using the following code:

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var text = ctx.measureText("foo"); // TextMetrics object
text.width; // 16; 

SpecificationsEdit

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'TextMetrics.width' in that specification.
Living Standard  

Browser compatibilityEdit

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.0 1.5 (1.8) 9.0 9.0 3.1

See alsoEdit

Document Tags and Contributors

 Contributors to this page: fscholz
 Last updated by: fscholz,