Control line width in JavaScript

Description

The following code shows how to control line width.

Example


<!DOCTYPE HTML>
<html>
<body>
<canvas id="canvas" width="500" height="500"></canvas>
<script>
var ctx = document.getElementById("canvas").getContext("2d");
ctx.lineWidth = 2;<!-- w ww  .  ja  va2  s.  c  o  m-->
ctx.strokeRect(30, 30, 50, 50);
ctx.lineWidth = 4;
ctx.strokeRect(70, 30, 50, 50);
ctx.lineWidth = 6;
ctx.strokeRect(130, 30, 50, 50);
ctx.strokeRect(190, 30, 50, 50);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Control line width in JavaScript