You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The read-only **`width`** property of the {{domxref("TextMetrics")}} interface contains the text's advance width (the width of that inline box) in CSS pixels.
## Examples
Start with this {{HTMLElement("canvas")}} element:
```html
<canvasid="canvas"></canvas>
```
You can get a {{domxref("TextMetrics")}} object using the following code:
```js
constcanvas=document.getElementById("canvas");
constctx=canvas.getContext("2d");
let text =ctx.measureText("foo"); // TextMetrics object