Draw a red square, on the fly, and show it inside the <canvas> element:
![]()
The <canvas> tag is supported in all major browsers.
The <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).
The <canvas> tag is only a container for graphics, you must use a script to actually draw the graphics.
The <canvas> tag is new in HTML5.
Note: Any text inside the <canvas> element will be displayed in browsers that does not support <canvas>.
Tip:For a complete reference of all the attributes and methods that can be used with the canvas object, go to our complete canvas 2d reference.
New : New in HTML5.
| Attribute | Value | Description |
|---|---|---|
| heightNew | pixels | Specifies the height of the canvas |
| widthNew | pixels | Specifies the width of the canvas |
The <canvas> tag also supports the Global Attributes in HTML5.
The <canvas> tag also supports the Event Attributes in HTML5.
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| Download XML Editor |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|