HTML5 Canvas distorted


If the canvas looks distorted, then try to change the height and width −

<canvas id = ”canvas1” width = '400' height = '300'></canvas>

The default height and width of the canvas in HTML5 is of 2/1 ratio −

width = 300
height = 150

Example

Let us see an example −

<!DOCTYPE HTML>
<html>
   <head>
      <style>
         #mycanvas{border:1px solid red;}
      </style>
   </head>
   <body>
      <canvas id = "mycanvas" width = "100" height = "100"></canvas>
   </body>
</html>

Output

Updated on: 16-Dec-2021

443 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements