Canvas rect() Method

Watch a demo of different values of the rect() method.

Or click a specific value to see the result:

rect(20,20,150,100);
rect(30,20,150,100);
rect(40,20,150,100);
rect(50,20,150,100);
rect(100,20,150,100);
rect(200,20,150,100);
your browser does not support the canvas tag
your browser does not support the canvas tag
your browser does not support the canvas tag
your browser does not support the canvas tag
your browser does not support the canvas tag
your browser does not support the canvas tag
const c = document.getElementById('myCanvas');
const ctx = c.getContext('2d');
ctx.beginPath();
ctx.rect(30,20,150,100);
ctx.stroke();

Play more with the code in our Tryit yourself editor: Try it Yourself ❯