<body> <script> var canvas = document.createElement('canvas'); canvas.id = "mycanvas"; canvas.width = 500; canvas.height = 500; canvas.style.position = "absolute"; canvas.style.border = "1px solid"; var body = document.getElementsByTagName("body")[0]; body.appendChild(canvas); var c = document.getElementById("mycanvas").getContext('2d'); c.fillRect(20,20,100,100); c.fillText("hello world", 200,200); </script> </body>