<canvas id="sample" width="140" height="140"></canvas> <script type="text/javascript"> var canvas = document.getElementById('sample'); var ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.moveTo(20, 20); ctx.lineTo(120, 20); ctx.lineTo(120, 120); ctx.lineTo(20, 120); ctx.fill(); ctx.stroke(); </script>