We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

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


readonly metrics.width;


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;


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

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support4 Yes1.5993.1
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support2.1 ? ?4 Yes3.2 ?

See also

Document Tags and Contributors

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