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 Darken an Image using CSS?
Next article icon

How to apply gradient as the mask using CSS ?

Last Updated : 20 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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 content of an element. There are mainly 2 types of Gradient that can be used as the mask layer in CSS:

  • Linear Gradient  
  • Radial gradient 

Table of Content

  • Linear Gradient
  • Linear Gradient with text masking
  • Radial Gradient

We will explore the above topics to include the gradient as the mask layer in CSS.

Linear Gradient

The property mask image with the linear-gradient is used to create a transition between the transparent area and the opaque area.

Syntax

// For Linear Gradient  mask-image: linear-gradient(rgb(24, 23, 23), transparent); 

Example: The following example illustrates the linear gradient as the mask layer.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width,                     initial-scale=1.0">     <title>CSS Gradient</title>          <style>         img {             height: 300px;             width: 300px;         }          .imgbox {             background-image: url( "https://media.geeksforgeeks.org/img-practice/prod/courses/1699342871/Web/Content/competitive-programming-cp-thumbnail.webp");             mask-image:                  linear-gradient(rgb(24, 23, 23), transparent);            -webkit-mask-image:                  linear-gradient(rgb(24, 23, 23), transparent);                 height: 500px;                 width: 600px;                 background-size: cover;         }         .gfg{             color: green;         }     </style> </head>  <body>     <h1 class="gfg">GeeksforGeeks</h1>     <p>Using Linear gradient as a mask layer:</p>     <div class="imgbox"></div>     <a href= "https://media.geeksforgeeks.org/img-practice/prod/courses/1699342871/Web/Content/competitive-programming-cp-thumbnail.webp">       Click to see the original image       </a> </body>  </html> 

Output:

linimg

Linear Gradient with Text Masking

The property mask-image with linear-gradient is used for masking the text to create a transition between the transparent area and the opaque area.

Example: The following example illustrates the linear gradient with text as the mask layer.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width,                     initial-scale=1.0">     <title>CSS Gradient</title>     <style>         .tbox {             background-color: aquamarine;             mask-image:                 linear-gradient(rgb(27, 22, 22), transparent);             -webkit-mask-image:                 linear-gradient(rgb(27, 22, 22), transparent);         }          .gfg {             color: green;         }          .ptext {             width: 500px;             font-size: 30px;             padding: 10px;          }          .texttitle {             font-size: 20px;         }     </style> </head>  <body>     <h1 class="gfg">GeeksforGeeks</h1>     <p class="texttitle">           Linear gradient as a mask layer:       </p>     <div class="tbox">         <p class="ptext">             Competitive Programming is a mental sport             which enables you to code a given problem             under provided constraints. The purpose of             this article is to guide every individual             possessing a desire to excel in this sport.             This article provides a detailed syllabus             for Competitive Programming designed by             industry experts to boost the preparation             of the readers.           </p>     </div> </body>  </html> 

Output:

lineartext

Radial Gradient

The property mask-image with radial-gradient is used to create a beautiful effect between transparent and opaque areas. The radial-gradient makes the effect of the circle or circle-like structure.

Syntax

// For Radial Gradient  mask-image: radial-gradient(circle at center, black 60%, rgba(0, 0, 0, 0.4) 40%); 

Example: The following example illustrates the Radial gradient as the mask layer with the shape circle.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"           content="width=device-width,                     initial-scale=1.0">     <title>CSS Gradient</title>      <style>         img {             height: 300px;             width: 300px;         }          .imgbox {             background-image: url( "https://media.geeksforgeeks.org/img-practice/prod/courses/1699342871/Web/Content/competitive-programming-cp-thumbnail.webp");             -webkit-mask-image:                 radial-gradient(circle at center,                                 black 60%,                                    rgba(0, 0, 0, 0.4) 40%);             mask-image:                 radial-gradient(circle at center,                                  black 60%,                                    rgba(0, 0, 0, 0.4) 40%);             height: 500px;             width: 600px;             background-size: cover;         }          .gfg {             color: green;         }     </style> </head>  <body>     <h1 class="gfg">GeeksforGeeks</h1>     <p>Using Radial gradient as a mask layer:</p>     <div class="imgbox">      </div>     <a href= "https://media.geeksforgeeks.org/img-practice/prod/courses/1699342871/Web/Content/competitive-programming-cp-thumbnail.webp"        alt="img">         Click to see the original image     </a> </body>  </html> 

Output:

radial

Next Article
How to Darken an Image using CSS?

S

shivanigupta18rk
Improve
Article Tags :
  • Web Technologies
  • CSS
  • 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 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 Darken an Image using CSS?
    To darken an image using CSS, the filter property with the brightness function and background-image property is used. By setting the brightness value below 1, you can reduce the lightness of the image, making it appear darker. 1. Using the filter PropertyThe CSS filter property allows you to apply v
    2 min read
  • How to Animate Gradient Background Smoothly Using CSS ?
    Animating gradient backgrounds smoothly using CSS means setting a gradient background and using transitions or keyframe animations to create gradual changes in colors, angles, or positions. This technique adds a dynamic and visually attractive effect to enhance the webpage's design. What is Gradient
    2 min read
  • How to Apply Shadow Effect on Text Using CSS?
    The CSS text-shadow property is used to add a shadow to the text. Adding a shadow to text using CSS text-shadowThe text-shadow property of CSS is used to apply the shadow effect on text. It takes four values verticalShadow, horizontalShadow, blur, and color. Syntax text-shadow: verticalShadow horizo
    1 min read
  • How to apply background image with linear gradient using Tailwind CSS ?
    In this article, we will see how to apply background images with a linear gradient using Tailwind CSS. Tailwind CSS is a highly customizable, utility-first CSS framework from which we can use utility classes to build any design. To apply background images with linear gradients we use the background
    2 min read
  • How to create linear gradient text by using HTML ?
    Creating linear gradient text on a webpage can add a dynamic and visually interesting touch to the design. While it is typically created using CSS, it is also possible to create linear gradient text using only HTML. Approach: Using the `<svg>` Element: The `<svg>` element in HTML provide
    2 min read
  • How to rotate an element using CSS ?
    The purpose of this article is to rotate an HTML element by using CSS transform property. This property is used to move, rotate, scale and to perform various kinds of transformation of elements. The rotate() function can be used to rotate any HTML element or used for transformations. It takes one pa
    1 min read
  • How to Add a Gradient Overlay to Text with CSS?
    Adding a gradient overlay to text can create visually appealing effects that enhance the design of a website. CSS provides various techniques to apply gradients to text. Table of Content Approach 1: Using background-clipApproach 2: Using a MaskApproach 3: Using SVGGradient Overlay to Text using back
    2 min read
  • How to Add Gradients to Your Project Using CSS?
    Gradients in CSS are used for creating visually appealing and dynamic backgrounds, text effects, and UI elements. They consist of smooth transitions between two or more colors and are widely used in modern web design. CSS offers three main types of gradients: linear, radial, and conic, each with uni
    5 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