HTML <canvas> tag

You are Here:

HTML <canvas> tag

The <canvas> tag is used to draw graphics via JavaScript.

This tag can also be used to draw graphs, combine photos, or create simple animations.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <canvas id="myCanvas">Your browser does not support the HTML5 canvas tag.</canvas> <script> // Draw Rectangle var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.fillStyle = "#248f24"; ctx.fillRect(0, 0, 150, 100); </script> </body> </html>

Tips

It is not recommended to learn canvas while taking html tutorial. Please navigate to Canvas tutorial after learning basic javascript.

Attributes

The following are the attributes of <canvas> tag. Also try Global attributes.

AttributeValueExplanation
widthpxSpecifies the width of the canvas.
heightpxSpecifies the height of the canvas.

Reminder

Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author