The box-shadow
property in CSS is used to add shadow effects around an element's frame. It can take several parameters to define the appearance and behavior of the shadow. Here are the parameters it can accept:
box-shadow [inset] offset-x offset-y [blur-radius] [spread-radius] [color];
inset
keyword is included, this changes the shadow from an outer shadow (one that falls outside of the box) to an inner shadow.offset-x: The horizontal distance to the right of the box where the shadow will be displayed. A negative value will place the shadow to the left of the box.
offset-y: The vertical distance below the box where the shadow will be displayed. A negative value will place the shadow above the box.
blur-radius (optional): This value determines the blur amount for the shadow, making it larger and lighter. The higher the value, the blurrier and bigger the shadow. If no value is set, the shadow will be sharp.
spread-radius (optional): This optional value allows the shadow to expand or shrink. Positive values will cause the shadow to expand and grow bigger than the source element, whereas negative values will cause it to shrink.
The box-shadow
can accept comma-separated values to create multiple shadows on the same element.
<offset-x>
<offset-y>
<offset-x>
<offset-y>
<blur-radius>
<offset-x>
<offset-y>
<blur-radius>
<spread-radius>
.box {
width: 100px;
height: 100px;
background-color: #666;
box-shadow: 10px 10px 20px 5px rgba(0, 0, 0, 0.5);
}
This will create a shadow that is offset 10 pixels to the right and 10 pixels down from the .box
, with a blur radius of 20 pixels and a spread radius of 5 pixels, using a semi-transparent black color.
Here are some examples online: