Canvas Strokerect
π
2026-06-14 | π HTML
## HTML Canvas strokeRect() Method
The `strokeRect()` method of the Canvas 2D API draws a rectangular outline (no fill) on the canvas. The default stroke color is black.
To customize the appearance of the outline (such as changing its color, gradient, or pattern), use the `strokeStyle` property before calling `strokeRect()`.
---
## Syntax
```javascript
context.strokeRect(x, y, width, height);
```
### Parameter Values
| Parameter | Type | Description |
| :--- | :--- | :--- |
| `x` | Number | The x-axis coordinate of the upper-left corner of the rectangle. |
| `y` | Number | The y-axis coordinate of the upper-left corner of the rectangle. |
| `width` | Number | The width of the rectangle in pixels. Positive values go to the right, while negative values go to the left. |
| `height` | Number | The height of the rectangle in pixels. Positive values go down, while negative values go up. |
---
## Browser Support
The `strokeRect()` method is widely supported across all modern web browsers:
* Google Chrome
* Mozilla Firefox
* Safari
* Opera
* Microsoft Edge / Internet Explorer 9+
*Note: Internet Explorer 8 and earlier versions do not support the `