What is CSS Masking?

What is CSS Masking?
Getting your Trinity Audio player ready...

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

Content Div
Mask Div

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 Effect
.gradient-mask {
    -webkit-mask-image: linear-gradient(to right, transparent, black);
    mask-image: linear-gradient(to right, transparent, black);
}

Shape Mask

Diamond Shape
.shape-mask {
    -webkit-mask-image: url('diamond.svg');
    mask-image: url('diamond.svg');
}

Interactive Mask

Hover Me!
.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

BrowserSupportNotes
ChromeYesFull support
FirefoxYesFull support
SafariYesRequires -webkit- prefix
EdgeYesFull support
IE 11NoNo support

Practical Applications

  • Image reveal effects on scroll
  • Creative hover states
  • Non-rectangular content displays
  • Text effects and animations
  • Progressive loading animations

Resources

MDN Web Docs

Comprehensive documentation on CSS masking properties

Read more

CSS Tricks

Practical examples and tutorials

Read more

Codepen

Interactive examples to experiment with

Explore

The Ultimate Guide to CSS Mask Animation

CSS Mask Div with Another Div- Complete Guide