CSS masking allows you to control the visibility of elements by using another element or image as a mask. The mask determines which parts of the element are visible and which are hidden.
Basic Concept
In this example, the black div is masking the image div with a circular cutout.
.mask-div {
mask-image: url('circle.svg');
-webkit-mask-image: url('circle.svg');
}
Different Masking Techniques
Gradient Mask
.gradient-mask {
-webkit-mask-image: linear-gradient(to right, transparent, black);
mask-image: linear-gradient(to right, transparent, black);
}
Shape Mask
.shape-mask {
-webkit-mask-image: url('diamond.svg');
mask-image: url('diamond.svg');
}
Interactive Mask
.interactive-mask {
-webkit-mask-size: 50% 50%;
mask-size: 50% 50%;
transition: all 0.5s ease;
}
.interactive-mask:hover {
-webkit-mask-size: 100% 100%;
mask-size: 100% 100%;
}
Browser Support
Browser | Support | Notes |
---|---|---|
Chrome | Yes | Full support |
Firefox | Yes | Full support |
Safari | Yes | Requires -webkit- prefix |
Edge | Yes | Full support |
IE 11 | No | No support |
Practical Applications
- Image reveal effects on scroll
- Creative hover states
- Non-rectangular content displays
- Text effects and animations
- Progressive loading animations
Resources
The Ultimate Guide to CSS Mask Animation
CSS Mask Div with Another Div- Complete Guide
Arsalan Malik is a passionate Software Engineer and the Founder of Makemychance.com. A proud CDAC-qualified developer, Arsalan specializes in full-stack web development, with expertise in technologies like Node.js, PHP, WordPress, React, and modern CSS frameworks.
He actively shares his knowledge and insights with the developer community on platforms like Dev.to and engages with professionals worldwide through LinkedIn.
Arsalan believes in building real-world projects that not only solve problems but also educate and empower users. His mission is to make technology simple, accessible, and impactful for everyone.