Open In App

How to create a gradient shadow using CSS ?

In this article, we will see how to create a gradient shadow using CSS, along with knowing the various CSS properties applied to get the gradient shadow effects.

The gradient shadow means adding the gradient with shadow effect to the element. The gradient can be linear, radial, or cylindrical. Generally, the gradient shadow can be implemented on the cards, buttons, banners, etc, to highlight it with a fake background outline, along with highlighting the content. Adding the gradient shadow can be achieved using CSS pseudo-classes, and linear-gradient shadows. 



Syntax:

element::after {
    /* desired styling properties */
}

Approach: Here are the steps required to get the desired linear-gradient shadow:



Example 1: This example describes the creation of a Linear-gradient shadow using CSS.




<!DOCTYPE html>
<html>
  
<head>
    <style>
        * {
            margin: auto;
        }
          
        .lgShadow {
            background: rgb(74, 201, 0);
            padding: 1rem;
            top: 100px;
            position: relative;
            height: 100px;
            width: 200px;
        }
        /* pseudo-class for making gradient shadow. */
          
        .lgShadow::after {
            content: "";
            position: absolute;
            inset: -.625em;
            background: linear-gradient(to bottom right,
                rgb(0, 255, 81), rgb(255, 213, 0));
            filter: blur(2.5em);
            z-index: -1;
        }
    </style>
</head>
  
<body>
    <p class="lgShadow">
        GeeksforGeeks is a portal for Geeks. 
    </p>
</body>
</html>

Output: 

Linear gradient shadow

Example 2: This example describes the Linear-gradient shadow in a circular shape using CSS.




<!DOCTYPE html>
<html>
  
<head>
    <style>
    * {
        margin: auto;
      }
      
    .lgShadow {
        background: rgb(201, 77, 0);
        padding: 3rem;
        top: 100px;
        position: relative;
        height: 100px;
        width: 200px;
        border-radius: 50%;
    }
    /* pseudo-class for making gradient shadow. */
      
    .lgShadow::after {
        content: "";
        position: absolute;
        inset: -.625em;
        background: linear-gradient(to bottom right, 
            rgb(255, 0, 0), rgb(255, 213, 0));
        filter: blur(2.5em);
        border-radius: 50%;
        z-index: -1;
    }
    </style>
</head>
  
<body>
    <p class="lgShadow">
        GeeksforGeeks is a portal for Geeks.
    </p>
</body>
</html>

Output:

Circular linear-gradient shadow


Article Tags :