Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas lineCap attribute

HTML canvas lineCap attribute

Canvas Object Reference Canvas object

Example

Draw a rounded line cap:

YourbrowserdoesnotsupporttheHTML5canvastag.

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();

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome and Safari support the lineCap attribute.

**Note:** Internet Explorer 8 and earlier versions do not support .


Definition and Usage

The lineCap attribute sets or returns the style of the cap at the end of a line.

Note:The "round" and "square" values make the line slightly longer.

Default value: butt
JavaScript syntax: context.lineCap="butt|round|square";

Attribute values

Value Description
butt Default. Adds a flat edge to each end of the line.
round Adds a round cap to each end of the line.
square Adds a square cap to each end of the line.

Canvas Object Reference Canvas object