Canvas Stroke
π
2026-06-18 | π HTML
## HTML Canvas stroke() Method
The `stroke()` method is a fundamental part of the HTML5 Canvas 2D Context API. It is used to actually draw (render) the path you have defined using methods like `moveTo()`, `lineTo()`, `arc()`, or `rect()`.
By default, the path is drawn as a solid black line with a width of 1 pixel.
---
## Definition and Usage
When you define a path in Canvas using drawing commands (such as `moveTo()` and `lineTo()`), you are creating an invisible mathematical outline. The `stroke()` method is what makes this outline visible on the screen by tracing it with a pen.
* **Default Color:** Black (`#000000`)
* **Default Line Width:** 1 pixel
* **Customization:** You can change the appearance of the stroke (color, gradient, or pattern) using the `strokeStyle` property, and the thickness using the `lineWidth` property before calling `stroke()`.
---
## Syntax
```javascript
context.stroke();
```
### Parameters
This method does not accept any parameters.
---
## Browser Support
The `stroke()` 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 `