box-shadow is a CSS property that lets you add shadow effects to any HTML element's box, including images, divs, buttons, or text containers. This shadow is applied directly to the element's box. This gives you full control over the shadow's color, blur, spread, and offset.
Syntax
box-shadow: offset-x offset-y blur-radius spread-radius color;
Example
.card {
box-shadow: 4px 4px 10px 0px rgba(0, 0, 0, 0.3);
}
Key Properties of box-shadow
- Offset-X / Offset-Y: Controls the horizontal and vertical position of the shadow.
- Blur-Radius: Adds a blur effect to the shadow to make it softer or sharper.
- Spread-Radius: Controls the size of the shadow; positive values increase the shadow size, while negative values shrink it.
- Color: Sets the color of the shadow.
When to Use box-shadow
box-shadow is perfect when you want to add shadows to a basic box, image, or element container, making it appear slightly elevated or giving it a soft glow. It works best with standard HTML elements without complex shapes.