Canvas lineCap attribute
Definition and usage
lineCap
Set or return the style of the line cap at the end of the line.
Note:"round
" and "square
" will make the line slightly longer.
Example
Draw the end line cap of the circle:
JavaScript:
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.beginPath(); ctx.lineCap="round"; ctx.moveTo(20,20); ctx.lineTo(20,200); ctx.stroke();
Syntax
context.lineCap="butt|round|square";
Attribute value
Value | Description |
---|---|
butt | Default. Add straight edges to each end of the line. |
round | Add circular line caps to each end of the line. |
square | Add square line caps to each end of the line. |
Technical Details
Default Value: | butt |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.