Home 〉 CSS Tutorials 〉 CSS box-shadow Tutorial: Create Stunning Shadows with Examples
CSS box-shadow Tutorial: Create Stunning Shadows with Examples !
Want to give depth to your elements? The `box-shadow` property helps you add shadows around boxes, making them look raised or sunken. Learn how to control horizontal and vertical shadows, blur, spread, and color. You can also create inner shadows and multiple shadow layers.
The 'box-shadow' property in CSS helps you create shadows behind elements like boxes, buttons, and cards. It adds depth and makes your design look more interactive and clean. This tutorial will walk you through everything you need to know — with easy examples and plain explanations.
The 'box-shadow' property applies a shadow to an element's frame (box). You can customize the shadow's position, blur, spread, and color.
Syntax ✍
box-shadow: offset-x offset-y blur-radius spread-radius color inset;
<!DOCTYPE html>
<html>
<head>
<style>
.box {
width: 200px;
height: 100px;
background: lightblue;
box-shadow: 4px 4px 10px gray;
}
</style>
</head>
<body>
<div class="box">Box with Shadow</div>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<head>
<style>
.inset-box {
width: 200px;
height: 100px;
background: #fefefe;
box-shadow: inset 3px 3px 10px rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<div class="inset-box">Inset Shadow</div>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<head>
<style>
.multi-shadow {
width: 200px;
height: 100px;
background: #fff;
box-shadow: 2px 2px 5px red, -2px -2px 5px blue;
}
</style>
</head>
<body>
<div class="multi-shadow">Multiple Shadows</div>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<head>
<style>
.hover-box {
width: 200px;
height: 100px;
background: #fff;
transition: box-shadow 0.3s;
}
.hover-box:hover {
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body>
<div class="hover-box">Hover Me</div>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The 'box-shadow' property is one of the simplest ways to improve UI design using pure CSS. It adds depth, helps focus attention, and makes your elements stand out. Once you master its syntax and effects, you'll be able to build cleaner and more modern interfaces with ease.
Yes! Use commas to add multiple shadows.
Blur makes the shadow soft; spread changes its size or coverage.
Set it to 'none' like: 'box-shadow: none;'.
Yes, it's supported in all major modern browsers.