HTML canvas strokeRect()Methods
Examples
Draw a 150*100 pixel rectangle:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.strokeRect(20,20,150,100);
var ctx=c.getContext("2d");
ctx.strokeRect(20,20,150,100);
Try it Yourself »
Browser Support
![]()
![]()
![]()
![]()
![]()
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the strokeRect() method.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
Definition and Usage
The strokeRect() method draws a rectangle (no fill). The default color of the stroke is black.
Tip:Use thestrokeStyleproperty to set the color, gradient, or pattern of the stroke.
| JavaScript Syntax: | context.strokeRect(x,y,width,height); |
|---|
Parameter Values
| Parameter | Description |
|---|---|
| x | The x-coordinate of the upper-left corner of the rectangle. |
| y | The y-coordinate of the upper-left corner of the rectangle. |
| width | The width of the rectangle, in pixels. |
| height | The height of the rectangle, in pixels. |
Other Extensions
Canvas Object