YouTip LogoYouTip

Met Canvas Strokerect

# HTML canvas strokeRect() Method [![Image 8: Canvas Object Reference Manual](#) Canvas Object](#) ## Example Draw a rectangle of 150*100 pixels: YourbrowserdoesnotsupporttheHTML5canvastag. JavaScript: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.strokeRect(20,20,150,100); [Try it »](#) * * * ## Browser Support ![Image 9: Internet Explorer](#)![Image 10: Firefox](#)![Image 11: Opera](#)![Image 12: Google Chrome](#)![Image 13: Safari](#) Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the strokeRect() method. **Note:** Internet Explorer 8 and earlier versions do not support the element. * * * ## Definition and Usage The strokeRect() method draws a rectangle (without filling). The default stroke color is black. **Tip:** Use the (#) property to set the stroke color, gradient, or pattern. | 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. | * * Canvas Object](#)
← Met Canvas ClearrectMet Canvas Fillrect β†’