<html>
<head>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<p>Click the button to create a CANVAS element, with drawings (a red rectangle).</p>
<script>
function myFunction() {
var x = document.createElement("CANVAS");
var ctx = x.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(20, 20, 150, 100);
document.body.appendChild(x);
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_canvas_create by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:04:41 GMT -->
</html>