<!DOCTYPE html>
<html>
<head>
<title>
HTML canvas strokeStyle property
</title>
</head>
<body>
<canvas id="GFG" width="500" height="300"></canvas>
<script>
var x = document.getElementById("GFG");
var context = x.getContext("2d");
// Create linear gradient
var gr = context.createLinearGradient(0, 0, 350, 200);
// Set color and position in a gradient object
gr.addColorStop("0", "green");
gr.addColorStop("0.7", "yellow");
gr.addColorStop("1.0", "blue");
// Set stroke style to gradient
context.strokeStyle = gr;
// Set line width
context.lineWidth = 5;
// Create rectangle
context.rect(50, 50, 350, 200);
context.stroke();
</script>
</body>
</html>