HTML | <canvas> width Attribute
The HTML <canvas> width Attribute is used to specify the width of the <canvas> in terms of pixels.
Syntax:
<canvas width="pixels">
Attribute Values: It contains the value i.e pixels which specify the width of the canvas in terms of pixel. It has a Default value which is 300.
Example: This Example illustrates the use of width attribute in Canvas Element.
<!-- HTML code to illustrate width attribute of canvas tag --><!DOCTYPE html> <html> <head> <title>HTML canvas Width attribute</title> </head> <body style="text-align:center;"> <h1>GeeksForGeeks</h1> <h2>HTML Canvas Width Attribute</h2> <canvas id="geeks" height="200" width="200" style="border:1px solid black"> </canvas> <script> var c = document.getElementById("geeks"); var cx = c.getContext("2d"); cx.beginPath(); cx.arc(100, 100, 90, 0, 2 * Math.PI); cx.stroke(); </script> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers:
- Google Chrome 4.0
- Firefox 2.0
- Edge 9.0
- Opera 9.0
- Apple Safari 3.1
Recommended Posts:
- HTML | <th> width Attribute
- HTML | <col> width Attribute
- HTML | <col> width Attribute
- HTML | <img> width Attribute
- HTML | <td> width Attribute
- HTML | <pre> width Attribute
- HTML | <hr> width Attribute
- HTML | <table> width Attribute
- HTML | <iframe> width Attribute
- HTML | <colgroup> width Attribute
- HTML | Marquee width attribute
- HTML | <object> width Attribute
- HTML <video> width Attribute
- HTML | <input> width Attribute
- HTML | <embed> width Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



