# lineWidth property

The `lineWidth` property sets the line width when drawing on the canvas.

## Syntax

`context.lineWidth = integer;`

## Example

Let's draw a line and set its width to `5` pixels:

`<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>` `let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.lineWidth = 5; // 5px width ctx.moveTo(50, 50); ctx.lineTo(150, 50); ctx.stroke();`

:

## Example

Width can also be changed for strokes, such as those drawn with `rect`:

`<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>` `let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.rect(50, 50, 100, 100); ctx.lineWidth = 5; ctx.stroke();`

:

## See also

- the `lineCap` property
  that sets the type of a line end
- the `lineJoin` property
  that sets lines join style

← →
↑
en ru