HTML canvas lineWidth Property
Example
Draw a rectangle with a line width of 10 pixels:
JavaScript:
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.lineWidth = 10;
ctx.strokeRect(20, 20, 80, 100);
Try it Yourself »
Description
The lineWidth property sets or returns the current line width, in pixels.
Default value: | 1 |
---|---|
JavaScript syntax: | context.lineWidth = number; |
Property Values
Value | Description | Play it |
---|---|---|
number | The current line width, in pixels | Play it » |
Browser Support
The <canvas>
element is an HTML5 standard (2014).
lineWidth
is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
❮ Canvas API