- HTML Canvas Tutorial
- HTML Canvas - Home
- HTML Canvas - Introduction
- Environmental Setup
- HTML Canvas - First Application
- HTML Canvas - Drawing 2D Shapes
- HTML Canvas - Path Elements
- 2D Shapes Using Path Elements
- HTML Canvas - Colors
- HTML Canvas - Adding Styles
- HTML Canvas - Adding Text
- HTML Canvas - Adding Images
- HTML Canvas - Canvas Clock
- HTML Canvas - Transformations
- Composting and Clipping
- HTML Canvas - Basic Animations
- Advanced Animations
- HTML Canvas API Functions
- HTML Canvas - Element
- HTML Canvas - Rectangles
- HTML Canvas - Lines
- HTML Canvas - Paths
- HTML Canvas - Text
- HTML Canvas - Colors and Styles
- HTML Canvas - Images
- HTML Canvas - Shadows and Transformations
- HTML Canvas Useful Resources
- HTML Canvas - Quick Guide
- HTML Canvas - Useful Resources
- HTML Canvas - Discussion
HTML Canvas - shadowBlur Property
The HTML Canvas shadowBlur property of Canvas 2D API is used to specify the blur amount to be applied to the graphic rendered inside the Canvas element.
Possible input values
The property takes positive float integer values where '0' represents no blur. The increase in number indicates more blur is to be applied.
Example
The following example draws a square onto the Canvas element and adds a shadow to it using the HTML Canvas shadowBlur property.
<!DOCTYPE html> <html lang="en"> <head> <title>Reference API</title> <style> body { margin: 10px; padding: 10px; } </style> </head> <body> <canvas id="canvas" width="300" height="200" style="border: 1px solid black;"></canvas> <script> var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); context.shadowColor = 'green'; context.shadowBlur = 20; context.fillStyle = 'blue'; context.fillRect(50, 25, 200, 150); </script> </body> </html>
Output
The output returned by the following code on the webpage as −
Example
The following example draws a circle onto the canvas element and adds a shadow to it using the property shadowBlur.
<!DOCTYPE html> <html lang="en"> <head> <title>Reference API</title> <style> body { margin: 10px; padding: 10px; } </style> </head> <body> <canvas id="canvas" width="200" height="150" style="border: 1px solid black;"></canvas> <script> var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); context.shadowColor = 'green'; context.shadowBlur = 50; context.fillStyle = 'grey'; context.arc(100, 75, 50, 0, 2 * Math.PI); context.fill(); </script> </body> </html>
Output
The output returned by the following code on the webpage as −
html_canvas_shadows_and_transformations.htm
Advertisements
To Continue Learning Please Login
Login with Google