English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML canvas lineWidth property

lineWidth is a Canvas 2D API sets the property for line thickness (i.e., the width of the line).

HTML canvas Reference Manual

Online Example

Using a width of 12 Draw rectangles with lines of pixels:

Your browser does not support HTML5 canvas tag.
<!DOCTYPE html>
<html>
<head>
<title>HTML canvas lineWidth property usage (Basic Tutorial Website oldtoolbag.com)</title>
</head>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3">
Your browser does not support HTML5 canvas tag.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.lineWidth=12;
ctx.strokeRect(20,20,80,100);
</script>
</body>
</html>
Test See ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 9Firefox, Opera, Chrome, and Safari support the lineWidth property.

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.

Definition and Usage

The lineWidth property sets or returns the current line width in pixels.

Default Value:1
JavaScript Syntax:context.lineWidth=number;

Attribute Value

 
ValueDescription
numberThe current line width, in pixels.
HTML canvas Reference Manual