Advertisement
Home Open Editor ❯

HTML canvas strokeRect() Method

Example

let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");

ctx.strokeRect(25, 25, 75, 50);

Try this code ❯

Meaning

The strokeRect() method draws a rectangle (no fill).


Standard Syntax

JavaScript syntax:

context.strokeRect(x,y,width,height);


Advertisement

Parameter Values

Parameter Description
x Specifies the x-coordinate of the upper-left corner of the rectangle.
y Specifies the y-coordinate of the upper-left corner of the rectangle.
width Specifies the width of the rectangle, in pixels.
height Specifies the height of the rectangle, in pixels.
Home Open Editor ❯
Advertisement