How to add a mask to an image using CSS ? Last Updated : 25 May, 2023 Comments Improve Suggest changes Like Article Like Report The mask-image property in CSS is used to set the mask of an image or text. CSS masking is used to form a mask layer for a particular element. You can add a mask to an image using the mask-image property in CSS. In this article, you will get to know the different property values of mask-image property and its different uses. Syntax: mask-image: none | <make-source> | <image> | inherit | initial | unset Property Value: none: No mask layer is set and a transparent black layer is set.<make-source>: Used to give the source of the image URL.<image>: Uses a linear gradient as a mask image.inherit: Inherit the mask property of the parent.initial: Applies the default setting of the property ie, match-source.unset: Discard the current mask property from the element. Example 1: Using <make-source> property value. Syntax: mask-image: url(); HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Using make-source property value</title> <style> body { background-color: #fff; } .container { width: 335px; height: 334px; background-image: url( "https://media.geeksforgeeks.org/wp-content/uploads/20210820105343/gfg.png"); background-size: cover; background-position: center; background-repeat: no-repeat; -webkit-mask-box-image: url(STAR.svg); mask: url(STAR.svg); } </style> </head> <body> <div class="container"></div> </body> </html> Output: Example 2: Using <image> property value. Syntax: mask-image: linear-gradient();Note: If there is 100% black in the image mask, then the image will be completely visible, anything that’s 100% transparent will be completely hidden, and anything in-between(0-100) will partially mask the image. HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Using image property</title> <style> body { background-color: #fff; } .container { width: 135px; height: 134px; background-image: url( "https://media.geeksforgeeks.org/wp-content/uploads/20210820105343/gfg.png"); background-size: cover; background-position: center; background-repeat: no-repeat; -webkit-mask-image: linear-gradient( to top, transparent 20%, black 80%); mask-image: linear-gradient( to top, transparent 20%, black 80%); } </style> </head> <body> <div class="container"></div> </body> </html> Output: In the above example, we are seeing that a semi-transparent image is hidden using the area. This glitch is caused by using the mask property Browser Support: ChromeFirefoxSafariOperaInternet Explorer Comment More infoAdvertise with us Next Article How to add a mask to an image using CSS ? aksrathod07 Follow Improve Article Tags : Web Technologies CSS CSS-Properties CSS-Questions Similar Reads How to add a button to an image using CSS ? In the article, we will explore how to add a button to an image using CSS. Adding a button to an image is often used to create an overlay effect to a button on an image that provides an interactive and engaging layout on a webpage. We can achieve this effect with the combination of various CSS Prope 4 min read How to add image refaction using CSS ? This article will show how to add image reflection using CSS. To achieve this task, you can use the -webkit-box-reflect to add the reflection of any HTML element. The box-reflect property is a CSS property that allows you to create a reflection effect for an element. It is primarily used to add a mi 2 min read How to Add Border to an Image Using HTML and CSS? Adding a border to an image means putting a line around the image to make it look better and more noticeable. To add a border to an image using HTML and CSS, we can use the <img> tag and apply CSS styles like border, border-width, and border color to customize the border's appearance.Syntax.im 1 min read How to Add filter to the background image using CSS? Adding filters to background images using CSS allows you to apply visual effects like blur, grayscale, brightness adjustment, and more without modifying the actual image file. CSS provides a set of filter functions that can be applied to elements with background images. This approach enhances design 3 min read How to add a black hover to an image using bootstrap? Bootstrap is a popular CSS framework widely used by frontend developers to create interactive UI for web applications. Bootstrap is widely used because of its simplicity and ease to use. Bootstrap allows multiple utilities to make images interactive. One of these utilities can be changing the color 4 min read Like