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

HTML Reference Manual

HTML tag大全

HTML canvas shadowOffsetX attribute

shadowOffsetX is a Canvas 2D API describes the attribute that specifies the horizontal offset distance of the shadow.

HTML canvas reference manual

Online Example

Draw a shadow on the right2A rectangle starting at 0 pixels (from the left side of the blue rectangle):

Your browser does not support HTML5 canvas tag.

HTML canvas shadowOffsetX attribute usage demonstration:

<!DOCTYPE html>
<html>
<head>
<title>HTML canvas shadowOffsetX attribute 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.shadowBlur=10;
ctx.shadowOffsetX=20;
ctx.shadowColor="black";
ctx.fillStyle="blue";
ctx.fillRect(20,20,100,80);
</script>
</body>
</html>
Test to see ‹/›

Browser compatibility

IEFirefoxOperaChromeSafari

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

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

Definition and usage

The shadowOffsetX property sets or returns the horizontal distance between the shadow and the shape.
shadowOffsetX = 0 means the shadow is exactly behind the shape.
shadowOffsetX = 20 means the shadow starts from the left side of the shape to the right20 pixels.
shadowOffsetX = -20 means the shadow starts from the left side of the shape to the left20 pixels.

Tip:To adjust the vertical distance of the shadow from the shape, please use shadowOffsetY Attribute.

Default value:0
JavaScript syntax:context.shadowOffsetX=number;

Attribute value

ValueDescription
numberPositive or negative value, defines the horizontal distance of the shadow from the shape.
HTML canvas reference manual