Related Articles

Related Articles

HTML | canvas shadowColor Property
  • Last Updated : 16 Apr, 2019

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).

Syntax::

context.shadowColor = color;

Parameters::
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.



Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<body>
    <canvas id="myCanvas"
            width="578" 
            height="400">
  </canvas>
    <script>
        var canvas = 
            document.getElementById('myCanvas');
        
        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);
    </script>
</body>
  
</html>

chevron_right


Output:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
  
    <canvas id="myCanvas"
            width="300"
            height="150">
  </canvas>
  
    <script>
        var c = 
            document.getElementById("myCanvas");
        
        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);
    </script>
</body>
  
</html>

chevron_right


Output:

Supported Browsers:

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

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :