The Wayback Machine - https://web.archive.org/web/20250219093702/https://www.geeksforgeeks.org/css-drop-shadow-function/
Open In App

CSS drop-shadow() Function

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The CSS drop-shadow() function adds a shadow effect to elements, like images, using horizontal and vertical offsets, blur radius, spread radius, and color parameters. It enhances visual depth and prominence in web design.

Syntax:

filter: drop-shadow(offset-x offset-y blur-radius spread-radius color);

Parameters: This function accepts five parameters as mentioned above and described below:

ParameterDescription
offset-xSets the horizontal offset of the shadow. Positive values move to the right; negative values move to the left.
offset-ySets the vertical offset of the shadow. Positive values move it down; negative move it up.
blur-radiusOptional parameter. Sets the blur radius of the shadow, creating a softer edge.
spread-radiusOptional parameter. Sets the spread radius of the shadow, expanding or contracting its size.
colorOptional parameter. Sets the color of the shadow. Default is black.

Examples of drop-shadow() Function in CSS

Example 1: Basic Usage

This example demonstrates the use of the drop-shadow() function to apply a yellow shadow with a 10px offset, blur radius, and spread radius to an image.

html
<!DOCTYPE html>
<html>

<head>
    <title>CSS drop-shadow() Function</title>

    <style>
        h1 {
            color: green;
        }

        body {
            text-align: center;
        }

        .drop_shadow_effect {
            filter: drop-shadow(10px 10px 10px yellow)
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>

    <h2>CSS drop-shadow() function</h2>

    <img class="drop_shadow_effect"
        src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"
        alt="GeeksforGeeks logo">
</body>

</html>

Output: 

Example 2: Negative Offsets

This example applies the  drop-shadow() function with negative offsets and a larger blur radius.

html
<!DOCTYPE html>
<html>

<head>
    <title>CSS drop-shadow() Function</title>

    <style>
        h1 {
            color: green;
        }

        body {
            text-align: center;
        }

        .drop_shadow_effect {
            filter: drop-shadow(10px 10px 10px yellow)
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>

    <h2>CSS drop-shadow() function</h2>

    <img class="drop_shadow_effect"
        src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"
        alt="GeeksforGeeks logo">
</body>

</html>

Output: 

Supported Browsers: The browsers supported by drop-shadow() function are listed below:

CSS drop-shadow() Function – FAQs

What is the drop-shadow() function in CSS?

The drop-shadow() function applies a shadow effect to an element, similar to box-shadow, but it works specifically with images and other graphical content.

How does drop-shadow() differ from box-shadow?

Unlike box-shadow, drop-shadow() can take into account the transparency of the content, applying the shadow to the shape of the content rather than the box boundary.

Can I apply multiple drop shadows using drop-shadow()?

Yes, you can apply multiple shadows by chaining drop-shadow() functions within the filter property, like filter: drop-shadow(…); drop-shadow(…);.

Can drop-shadow() be animated in CSS?

Yes, you can animate shadows created with drop-shadow() using CSS animations or transitions for effects like shadow movement or size change.

Does drop-shadow() work with SVG elements?

Yes, drop-shadow() works well with SVG elements, allowing you to apply shadows to complex vector graphics while respecting their shape and transparency.



Next Article

Similar Reads

three90RightbarBannerImg