Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas width attribute

HTML width property

HTML canvas Tag Reference HTML tag

Example

With a height and width of 200 pixels element:

Try it »


Browser support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the width property.

Note: Internet Explorer 8 and earlier IE versions are not supported. tag.


Definition and Usage

The width attribute returns the width of the ImageData object, in pixels.

Tip: Whenever the height or width of the canvas is reset, the canvas content is cleared (see the example at the bottom of the page).

Tip: Please see ourHTML Canvas Learn more about in the tutorial knowledge.


Differences between HTML 4.01 and HTML 5

is a new tag in HTML5.


Syntax

Attribute values

Value Description
pixels Specifies the width attribute of the canvas, in pixels (for example, "100"). The default width is "300"

More examples

Clear the canvas
How to clear the canvas by resetting the width or height attribute (using JavaScript).


HTML canvas Tag Reference HTML tag