The HTML DOM box-shadow property is used for getting or setting the shadow in or around the frame of an element.
Following is the syntax for −
Setting the boxShadow property −
box-shadow: none|h-offset v-offset blur spread color |inset|initial|inherit;
The property values are explained as follows −
Value | Description |
---|---|
none | This is the default value and displays no shadow. |
h-offset | This specifies how far the shadow will be from horizontal offset. It is a required value and positive value states that the shadow will be from right side of the box while the negative value means it will from left side of the box. |
v-offset | This specifies how far the shadow will be from vertical offset. It is a required value and positive value states that the shadow will be from bottom side of the box while the negative value means it will from top side of the box. |
blur | For specifying the blur radius. |
spread | For specifying the spread radius. |
color | For specifying the shadow color. |
inset | This makes the shadow come from outer to inner for an element. |
initial | For setting this property to initial value. |
inherit | To inherit the parent property value |
Let us look at an example for the boxShadow property −
Example
<!DOCTYPE html> <html> <head> <style> #DIV1 { height: 100px; width: 100px; box-shadow: 10px 10px 3px orange; } </style> <script> function changeBoxShadow(){ document.getElementById("DIV1").style.boxShadow="1px 10px 10px 10px green"; document.getElementById("Sample").innerHTML="The box shadow is changed now "; } </script> </head> <body> <div id="DIV1">This is a sample div</div> <p>Change the above div border width by clicking the below button</p> <button onclick="changeBoxShadow()">Change Box Shadow</button> <p id="Sample"></p> </body> </html>
Output
On clicking the “Change Box Shadow” button −