In this jsfiddle there\'s a line with a lineWidth of 1.
http://jsfiddle.net/mailrox/9bMPD/350/
e.g:
ctx.lineWidth = 1;
How
Did you see the first hit on google? (search for canvas line width 1px
).
Though I have to admit this isn't exactly "clean" or "lean". Ferry Kobus' solution is much better. Then again: it sucks you need to use "half pixels" in the first place...
You can also translate by half a pixel in the X and Y directions and then use whole values for your coordinates (you may need to round them in some cases):
context.translate(0.5, 0.5)
context.moveTo(5,5);
context.lineTo(55,5);
Keep in mind that if you resize your canvas the translate will be reset - so you'll have to translate again.
You can read about the translate function and how to use it here:
https://www.rgraph.net/canvas/reference/translate.html
This answer explains why it works that way.