Easy Tutorial
❮ Att Colgroup Align Av Prop Currenttime ❯

HTML <canvas> width Attribute

HTML <canvas> Tag

Example

A <canvas> element with a height and width of 200 pixels:


Browser Support

All major browsers support the width attribute.

Note: The <canvas> tag is not supported in Internet Explorer 8 and earlier versions.


Definition and Usage

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

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

Tip: Learn more about <canvas> in our HTML Canvas tutorial.


Differences Between HTML 4.01 and HTML 5

<canvas> is a new tag in HTML5.


Syntax

Attribute Values

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

More Examples

Clearing the Canvas


HTML <canvas> Tag

❮ Att Colgroup Align Av Prop Currenttime ❯