HTML canvas width attribute
Examples
Height and width of 200 pixels <canvas> element:
<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
try it"
Browser Support
All major browsers support width attribute.
Note: Internet Explorer 8 and earlier versions of IE do not support the <canvas> tag.
Definition and Usage
width width ImageData property returns an object, in pixels.
Tip: Whenever canvas height or width is reset, the contents of the canvas will be empty (see examples at the bottom of the page).
Tip: In our HTML Canvas learn more about <canvas> knowledge tutorial.
HTML 4.01 and HTML 5 differences between
<Canvas> tag is new in HTML5.
grammar
<canvas width="pixels">
Property Value
Value | Description |
---|---|
pixels | 指定 canvas 的 width属性, 以像素计(如"100")。 默认 width 为 "300" |
More examples
Empty Canvas
How to reset the width or height attribute to clear the canvas (using JavaScript).