X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML <canvas> width Attribute

HTML canvas Tag Reference HTML <canvas> tag

Example

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

<canvas id="myCanvas" width="200" height="200" style="border:1px solid">

Try it yourself »

More "Try it Yourself" examples below.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The width attribute is supported in all major browsers.

Note: Internet Explorer 8 and earlier versions, do not support the <canvas> tag.


Definition and Usage

The width attribute specifies the width of the <canvas> element, in pixels.

Tip: Each time the height or width of a canvas is re-set, the canvas content will be cleared (see example at bottom of page).

Tip: Learn more about the <canvas> element in our HTML5 Canvas Tutorial.


Differences Between HTML 4.01 and HTML5

The <canvas> tag is new in HTML5.


Syntax

<canvas width="pixels">

Attribute Values

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


Examples

Try it Yourself - Examples

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


HTML canvas Tag Reference HTML <canvas> tag

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook