Draw Rectangle in Canvas in HTML5


<html>
	<head>
		<title>Draw Rectangle in Canvas in HTML5</title>
	</head>
	<body>

		<canvas id="mycanvas" width="300" height="300" style="border: 1px solid black;"></canvas>
		<br>
		<input type="button" value="Draw Rectangle" onclick="drawRectangle()">

		<script type="text/javascript">

			function drawRectangle() {
				var mycanvas = document.getElementById('mycanvas');
				var ctx = mycanvas.getContext('2d');
				ctx.fillStyle = 'blue';
				ctx.fillRect(50, 50, 200, 100);
			}

		</script>

	</body>
</html>




Open site in browser and display as below: