Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Create an attenuated shadow with CSS
CSS shadows can be created using the box-shadow and text-shadow properties to add depth and visual appeal to elements. These properties allow you to create attenuated (softened) shadows with customizable direction, color, and blur effects.
Syntax
/* Box shadow syntax */ box-shadow: h-offset v-offset blur spread color; /* Text shadow syntax */ text-shadow: h-offset v-offset blur color;
Parameters
| Parameter | Description |
|---|---|
| h-offset | Horizontal offset of the shadow (positive = right, negative = left) |
| v-offset | Vertical offset of the shadow (positive = down, negative = up) |
| blur | Blur radius - higher values create more attenuated shadows |
| spread | Shadow spread (box-shadow only) - expands or contracts the shadow |
| color | Shadow color using hex, RGB, or color names |
Example: Box Shadow
The following example creates an attenuated shadow on a box element −
<!DOCTYPE html>
<html>
<head>
<style>
.shadow-box {
width: 200px;
height: 100px;
background-color: #4CAF50;
margin: 50px;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-family: Arial, sans-serif;
box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body>
<div class="shadow-box">Box with Shadow</div>
</body>
</html>
A green box with a soft, attenuated shadow appearing 10px to the right and 10px below the element with a 20px blur radius.
Example: Text Shadow
The following example creates an attenuated shadow on text −
<!DOCTYPE html>
<html>
<head>
<style>
.shadow-text {
font-size: 30px;
font-family: Arial Black, sans-serif;
color: #FF6B6B;
text-align: center;
margin: 50px;
text-shadow: 5px 5px 10px rgba(0, 0, 139, 0.5);
}
</style>
</head>
<body>
<h2 class="shadow-text">CSS Tutorials</h2>
</body>
</html>
Large red text "CSS Tutorials" with a blue attenuated shadow offset 5px to the right and 5px down with a 10px blur effect.
Example: Multiple Shadows
You can create multiple shadows by separating them with commas −
<!DOCTYPE html>
<html>
<head>
<style>
.multi-shadow {
width: 150px;
height: 150px;
background-color: #FF6B6B;
margin: 50px auto;
border-radius: 50%;
box-shadow:
5px 5px 15px rgba(0, 0, 0, 0.3),
-5px -5px 15px rgba(255, 255, 255, 0.5),
inset 3px 3px 10px rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<div class="multi-shadow"></div>
</body>
</html>
A circular red element with multiple layered shadows creating a 3D effect with outer shadows and an inner shadow.
Conclusion
CSS shadows using box-shadow and text-shadow provide powerful ways to create attenuated shadow effects. The blur parameter is key to creating soft, realistic shadows that enhance visual depth.
Advertisements
