Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

JavaScript - how to set line width (thickness / size) drawing on canvas element?

0 contributions
2 points

Simple solution:

context.lineWidth = 20; // 20px

// line from x1=10, y1=20 to x2=200, y2=100
context.moveTo(10, 20);
context.lineTo(200, 100);


Using JavaScript it is possible to draw line in following way.

1. lineTo method example

// ONLINE-RUNNER:browser;

<!doctype html>
    #my-canvas { border: 1px solid gray; }
  <canvas id="my-canvas" width="200" height="200"></canvas>

    var canvas = document.querySelector('#my-canvas');
    var context = canvas.getContext('2d');

    function drawLine() {

        context.lineWidth = 20;

        context.moveTo(10, 50);
        context.lineTo(170, 150);



Merged questions

  1. JavaScript - canvas line with lineWidth property example
0 contributions

Suggested wiki articles:

Suggested findings

Let's do the work and have some fun
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way. ❤ 💻 🙂
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    we will help you. 👍 ✔ 🦄
Read more