Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 5

How do you get a thicker stroke when drawing on the canvas?

Tried to get a wider line when I was drawing, how to?

1 Answer

Lucas Santos
Lucas Santos
19,315 Points

By using lineWidth

**Simple Example*

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.lineWidth = 10;
ctx.strokeRect(20, 20, 80, 100);

</script>

</body>
</html>

We set it to 10 here:

ctx.lineWidth = 10;
Niels Anders
Niels Anders
7,408 Points

And when for example the lineWidth = 10 and the edges are not smooth when you draw. context.lineCap = "round"; // or square etc..