The CanvasRenderingContext2D
.lineJoin
property of the Canvas 2D API determines the shape used to join two line segments where they meet.
This property has no effect wherever two connected segments have the same direction, because no joining area will be added in this case. Degenerate segments with a length of zero (i.e., with all endpoints and control points at the exact same position) are also ignored.
See also the chapter Applying styles and color in the Canvas tutorial.
ctx.lineJoin = "bevel" || "round" || "miter";
There are three possible values for this property: "round"
, "bevel"
, and "miter"
. The default is "miter"
.
"round"
"bevel"
"miter"
miterLimit
property.lineJoin
propertyThis is just a simple code snippet using the lineJoin
property.
<canvas id="canvas"></canvas>
var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.lineWidth = 20; ctx.lineJoin = 'round'; ctx.beginPath(); ctx.moveTo(20, 20); ctx.lineTo(200, 100); ctx.lineTo(300, 20); ctx.lineTo(300, 160); ctx.stroke();
Edit the code below to see your changes update live in the canvas:
The example below draws three different paths, demonstrating each of the three lineJoin
options.
var ctx = document.getElementById('canvas').getContext('2d'); var lineJoin = ['round', 'bevel', 'miter']; ctx.lineWidth = 10; for (let i = 0; i < lineJoin.length; i++) { ctx.lineJoin = lineJoin[i]; ctx.beginPath(); ctx.moveTo(-5, 5 + i * 40); ctx.lineTo(35, 45 + i * 40); ctx.lineTo(75, 5 + i * 40); ctx.lineTo(115, 45 + i * 40); ctx.lineTo(155, 5 + i * 40); ctx.stroke(); }
Screenshot | Live sample |
---|---|
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'CanvasRenderingContext2D.lineJoin' in that specification. | Living Standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | 12 | Yes | Yes | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
ctx.setLineJoin()
is implemented in addition to this property.CanvasRenderingContext2D
CanvasRenderingContext2D.lineCap
CanvasRenderingContext2D.lineWidth
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin