CSS Shadow Effects

CSS Shadow Effects allow you to add depth and emphasis to elements on a web page. The most common shadow effects are text-shadow and box-shadow. These effects are versatile and widely used in modern web design.

Key Topics

Text Shadow

The text-shadow property adds shadows to text. You can specify the horizontal offset, vertical offset, blur radius, and color of the shadow.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Text Shadow</title>
    <style>
        .text-shadow {
            font-size: 24px;
            font-weight: bold;
            color: #007BFF;
            text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
            margin: 20px;
        }
    </style>
</head>
<body>
    <p class="text-shadow">This text has a shadow effect.</p>
</body>
</html>

Explanation: The text-shadow property applies a shadow with a 2px horizontal and vertical offset, a 5px blur radius, and a semi-transparent black color.

Box Shadow

The box-shadow property applies shadows to elements like divs or boxes. You can specify horizontal and vertical offsets, blur radius, spread radius, and color.

<style>
        .box-shadow {
            width: 200px;
            height: 100px;
            background-color: #007BFF;
            color: white;
            text-align: center;
            line-height: 100px;
            margin: 20px;
            box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
        }
</style>
<div class="box-shadow">Box Shadow</div>

Explanation: The box-shadow property applies a shadow with a 5px horizontal and vertical offset, a 10px blur radius, and a semi-transparent black color to the box.

Key Takeaways

  • Text Shadow: Use text-shadow for adding emphasis and depth to text.
  • Box Shadow: Use box-shadow for creating depth and highlighting boxes or containers.
  • Customization: Adjust offsets, blur radius, spread radius, and color to create unique shadow effects.
  • Performance: Excessive use of shadows may affect rendering performance on slower devices.