I need to draw a line and give it a border.
I tried to draw two lines, one 5px and above 3px
But that doesn't exactly seem like a real border
const ctx = canvas.getContext('2d');
const path = new Path2D();
ctx.strokeStyle = "black";
ctx.lineWidth = 5;
path.moveTo(40, 40);
path.lineTo(50, 35);
path.lineTo(60, 40);
ctx.stroke(path);
ctx.strokeStyle = "red";
ctx.lineWidth = 3;
path.moveTo(40, 40);
path.lineTo(50, 35);
path.lineTo(60, 40);
ctx.stroke(path);
<canvas id=canvas width=100 height=100></canvas>
Is there a better way to draw a border for a line?
You could try with shadow:
The idea is to draw with a slightly different offset all-around your path object ... and that same logic can be used for images:
https://raw.githack.com/heldersepu/hs-scripts/master/HTML/canvasOutline.html