HTML DOM Style boxShadow Property


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 −

ValueDescription
noneThis is the default value and displays no shadow.
h-offsetThis 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-offsetThis 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.
blurFor specifying the blur radius.
spreadFor specifying the spread radius.
colorFor specifying the shadow color.
insetThis makes the shadow come from outer to inner for an element.
initialFor setting this property to initial value.
inheritTo inherit the parent property value

Let us look at an example for the boxShadow property −

Example

 Live Demo

<!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 −

Updated on: 23-Oct-2019

42 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements