Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to create a drop shadow effect using CSS ?
Next article icon

How to Create a Gradient Shadow using CSS ?

Last Updated : 16 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A gradient shadow in CSS refers to creating a shadow effect that transitions smoothly from one color to another, using gradients. While the box-shadow property doesn’t support gradients directly, you can simulate this effect by layering a semi-transparent gradient as the background or using pseudo-elements.

Create a Gradient Shadow in CSS

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

  • Create an HTML element (button, card, etc.) for the shadow effect.
  • Use a pseudo-class ::before or ::after in CSS with absolute positioning relative to the parent element.
  • Apply small insets (top, right, bottom, left) to adjust the shadow’s position.
  • Set a linear-gradient as the background for the pseudo-class, specifying the colors and direction.
  • Use the filter: blur() property to soften the shadow, simulating a realistic effect.
  • Add a z-index to ensure the shadow appears beneath the parent element.

Example 1: Linear-gradient Shadow on a Rectangle

Here we creates a rectangular element with a linear-gradient shadow effect using a pseudo-element.

HTML
<!DOCTYPE html> <html>  <head>     <title>Linear-gradient Shadow on a Rectangle</title>     <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-on-a-Rectangle

Linear-gradient Shadow on a Rectangle

Example 2: Circular Gradient Shadow

Here we displays a circular element with a gradient shadow effect, enhancing the appearance of the text “GeeksforGeeks” while maintaining a visually appealing design.

HTML
<!DOCTYPE html> <html>  <head>     <title>Circular Gradient Shadow</title>     <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-Gradient-Shadow

Circular Gradient Shadow




Next Article
How to create a drop shadow effect using CSS ?

S

satyamm09
Improve
Article Tags :
  • CSS
  • Web Technologies
  • CSS-Properties
  • CSS-Questions

Similar Reads

  • How to create a gradient shadow using CSS ?
    A gradient shadow in CSS refers to creating a shadow effect that transitions smoothly from one color to another, using gradients. While the box-shadow property doesn't support gradients directly, you can simulate this effect by layering a semi-transparent gradient as the background or using pseudo-e
    2 min read
  • How to create a drop shadow effect using CSS ?
    In this article, we are going to learn how to create a drop shadow effect using CSS. drop-shadow() is an inbuilt function used to create a blurred shadow in a given offset and color. A drop shadow effect adds depth and visual interest to elements on a web page by creating a shadow behind them. This
    3 min read
  • How to create linear gradient background using CSS ?
    In CSS, we can use the background-color property to set the background color of an element to a specific color. Sometimes we want to add more styling to the element when setting the background color by using the linear-gradient property. CSS linear-gradient property lets you display smooth transitio
    4 min read
  • How to create linear gradient text using HTML and CSS ?
    The linear-gradient is used to create eye-catching text effects, particularly suitable for dark-themed websites or applications. This method involves filling text with linear-gradient color codes, making it look attractive and bold. Linear-gradient text effects are ideal for dark themes and provide
    3 min read
  • How to create gradient search button using HTML and CSS ?
    In this article, we will see how to create a gradient search button using HTML & CSS, along with knowing its basic implementation through the examples. The creation of a gradient search button involves the CSS linear-gradient() function, which sets the background color of the button. Here, we ha
    4 min read
  • How to apply gradient as the mask using CSS ?
    In this article, we will learn how to include the gradient as the mask layer in CSS, along with understanding their basic implementation with the help of suitable examples. The Mask Property with a Gradient is used to create a mask layer, that can be utilized for rendering or hiding the area of the
    3 min read
  • How to create a gradient navbar using HTML and Inline CSS ?
    A gradient navbar is a stylish way to make your website look modern and professional. In this article, we will show you how to create a gradient navbar using HTML only. No CSS or JavaScript is required. Approach: Please refer linear-gradient() method to create a gradient background. This HTML code u
    4 min read
  • Create a Glowing text shadow using HTML and CSS
    To create a glowing text-shadow, we will use HTML to create the structure and CSS for the styling of the text. With the help of CSS, we can add shadows to text. HTML Code: In this section, we will design the basic structure of the code. C/C++ Code <!DOCTYPE html> <html lang="en"
    2 min read
  • How to create a marquee effect using CSS ?
    In this article, we will be creating the marquee effect by using HTML and CSS. This effect can be created by using the <marquee> tag in HTML, but we will not use this tag as it is not widely used nowadays. We will create and design a marquee effect by using the CSS classes and styling properti
    2 min read
  • How to create fading buttons using CSS ?
    This article will explore how to create fading buttons using CSS. We can create two types of fading effects in buttons including fadeIn and FadeOut. The CSS property opacity is used to give a fading effect on hovering the button. Fading buttons offer an effective way to provide a pleasing visual eff
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences