Skip to content
Related Articles

Related Articles

Improve Article

HTML | canvas shadowColor Property

  • Last Updated : 16 Apr, 2019
Geek Week

The Canvas shadowColor property is used to set or returns the color that is used for shadows. The fillStyle property is used to create shadows. This property can be set to a string representing a CSS color value, which we want as shadow color.
By default, shadow color is set to black (CSS color value #000000).


context.shadowColor = color;

color: This parameter indicates a css color value which is to be used as shadow color of the drawing.

The shadowColor property together with the shadowBlur property to create a shadow. Also the adjustment of the shadow can be done by using the shadowOffsetX and shadowOffsetY properties.

context.shadowOffsetX : This indicates the x offset of shadow. It can be positive or negative.
context.shadowOffsetY : This indicates the y offset of shadow. It can be positive or negative.
context.shadowBlur : This indicates the blur filter diffusion of the shadow. The higher the number, the more diffusion.


    <canvas id="myCanvas"
        var canvas = 
        var context = canvas.getContext('2d');
        context.font = "35px Helvetica";
        context.shadowOffsetX = 3;
        context.shadowOffsetY = 3;
        context.fillText("GeeksforGeeks", 190, 100);
        context.shadowColor = "rgba(0, 0, 0, 0.5)";
        context.fillText("GeeksforGeeks", 190, 160);
        context.shadowBlur = 1;
        context.fillText("GeeksforGeeks", 190, 220);



<!DOCTYPE html>
    <canvas id="myCanvas"
        var c = 
        var ctx = c.getContext("2d");
        ctx.shadowBlur = 20;
        ctx.fillStyle = "green";
        ctx.shadowColor = "yellow";
        ctx.fillRect(20, 20, 100, 80);
        ctx.shadowColor = "blue";
        ctx.fillRect(140, 20, 100, 80);


Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Edge 9.0
  • Safari
  • Opera

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :