×

CSS Masking

CSS Masking

The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use of a graphical image or an image like the alpha mask or luminance. It can be any graphical operation, i.e., partially or fully hide the component’s portions or object.

It can be possible to hide or show the image’s part along with the distinct opacity levels with the use of masking. The masking can be achieved using the CSS mask-image attribute, and we must give any image like the mask.

The following are some examples of CSS masking.

Example:1

In the following example, we will position the mask over an image component. There will be two particular images, and we will apply to mask over them, the concluding image created by putting a mask image entirely together.

<!DOCTYPE html> 
<html> 
<head> 
<style> 
div img{ 
width: 200px; 
height: 200px; 
} 
#masked{ 
width: 300px; 
height: 300px; 
-webkit-mask-box-image: url(circle1.png) 25; 
} 
</style> 
</head> 
<body> 
<center> 
<div id = "one"> 
<h2> Original Images </h2> 
<img src = "flower4.jpg"> 
<img src = "circle1.png"> 
</div> 
<h2> After masking </h2> 
<img src = "flower4.jpg" id = "masked"> 
</center> 
</body> 
</html> 

Output:

Example: 2

In the following example, here are other illustrations where we will use masking on the images. We will apply two pictures where one of the pictures is the mask picture that includes stripes. The illustration will show the positioning the mask on a picture component as mentioned below.

<!DOCTYPE html> 
<html> 
<head> 
<style> 
div img{ 
width: 200px; 
height: 200px; 
} 
#masked{ 
width: 300px; 
height: 300px; 
-webkit-mask-box-image: url(stripes.png); 
background-color: black; 
} 
</style> 
</head> 
<body> 
<center> 
<div id = "one"> 
<h2> Original Images </h2> 
<img src = "flower4.jpg"> 
<img src = "stripes.png"> 
</div> 
<h2> After masking </h2> 
<img src = "flower4.jpg" id = "masked"> 
</center> 
</body> 
</html> 

Output:

Example: 3

We may apply the gradients of CSS like the mask image’s source.

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#masked
{ 
width: 300px; 
height: 300px; 
-webkit-mask-image: -webkit-gradient(linear, right top, right bottom, from(rgba(0,0,0,0)), to(rgba(0,0,0,0.9))); 
border: 9px ridge green; 
} 
</style> 
</head> 
<body> 
<center> 
<img src = "flower4.jpg" id = "masked"> 
</center> 
</body> 
</html> 

Output:

Example: 4

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#masked
{ 
width: 300px; 
height: 300px; 
border-radius: 0px; 
-webkit-mask-image: radial-gradient(circle at 50% 50%, blue 40%, rgba(0,0,0,0.3) 70%); 
border: 9px ridge green; 
} 
</style> 
</head> 
<body> 
<center> 
<img src = "flower4.jpg" id = "masked"> 
</center> 
</body> 
</html> 

Output:

CSS Masking

Example: 5

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#circle
{ 
width: 300px; 
height: 300px; 
-webkit-mask-image: radial-gradient(circle at 50% 50%, blue 40%, rgba(0,0,0,0.3) 70%); 
border: 9px ridge green; 
} 
#ellipse
{ 
width: 300px; 
height: 300px; 
-webkit-mask-image: radial-gradient(ellipse 80% 30% at 50% 50%, blue 40%, rgba(0,0,0,0.3) 55%); 
border: 9px ridge green; 
} 
</style> 
</head> 
<body> 
<center> 
<img src = "flower4.jpg" id = "circle"> 
<img src = "flower4.jpg" id = "ellipse"> 
</center> 
</body> 
</html> 

Output:

CSS Masking

Related Topics

How to change font size in CSS

How to change font size in CSS? Font Size: - Users may attract attention to content on a website page in various ways. One element in a sentence can be highlighted. You...

5 minutes read.

CSS Button Style

CSS button style: Using CSS properties, we can easily modify the default BUTTON and enhance its appearances using simple graphic commands. TYPES OF BUTTON STYLE: - Program to change button using CSS ...

35 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 minutes read.

CSS Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

CSS Descendant Selector

Descendant Selector The Descendant selector in CSS is used to match the descendant components of a particular component. The term descendant depicts nested in whatever place, inside a DOM tree. This...

2 minutes read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

CSS Dropdowns

Dropdowns are one of the maximum crucial parts of an interactive internet site. CSS is a kind used to design the drop-down menus. A drop-down essentially is a group of...

5 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

Css Text Orientation

Introduction: The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not...

4 minutes read.

CSS Sticky

CSS Sticky The position property in CSS is applied to set an element’s position. This property is also applied to position an element behind the other element. It is useful for...

1 minute read.

How to include CSS

How to include CSS CSS is included in HTML pages for formatting the documents based on the information inside a style sheet. We can add CSS in HTML documents in the following three ways: Inline...

5 minutes read.

CSS Background-clip

CSS Background-clip: The background-clip property describes the background’s painting area. It limits an area where the image or color of the background appears by using any clipping box. Everything will...

2 minutes read.

CSS Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

CSS Superscript and Subscript

Superscript and Subscript To specify the superscript and the subscript text, HTML provides us two tags that are <sup> and <sub>. The superscript content looks in the shorter font and half...

2 minutes read.

CSS White Space Property

White Space in CSS The white-space CSS property describes how to show the content inside an element. This property is applied to manage a white space within an element. Values of White-space...

2 minutes read.