The canvas tag in HTML
- 24-07-2022
- Trung Minh
- 0 Comments
The <canvas> tag is used to draw graphics directly on the page, through the use of scripting (usually javascript).
The <canvas> tag is just a graphics container, you must use a script to draw the graphics.
How to use the <canvas> . tag
For example , use the <canvas> tag to draw.
<!DOCTYPE html> <html> <head> <title>Học lập trình miễn phí tại web888.vnt</title> <meta charset="utf-8"> </head> <body> <h1>Học lập trình miễn phí tại web888.vn</h1> <canvas id="myCanvas">Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.fillStyle = "#FF0000"; ctx.fillRect(0, 0, 80, 100); </script> <p> <strong>Note:</strong> The canvas tag is not supported in Internet Explorer 8 and earlier versions. </p> </body> </html>
Attribute of <canvas> . tag
- height – the height of the same graphic.
- width – the width of the graphics area.