Changing a line width in canvas in JavaScript

The line width is set using the lineWidth property. Just give it a width, like this: lineWidth = 5 - you get a line width of 5px. Let's look at an example:

html<canvas width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('canvas');
let ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.lineWidth = 5; // width of 5px
ctx.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.stroke();

Результат:

A width can also be changed for outlines, such as those drawn with rect:

html<canvas width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('canvas');
let ctx = canvas.getContext('2d');

ctx.rect(50, 50, 100, 100);
ctx.lineWidth = 5;
ctx.stroke();

Результат: