π What Is mask-mode?
The mask-mode property controls how the mask image is interpreted β either by its alpha channel (transparency) or by its luminance (brightness).
This determines how much of the masked element is visible.
In simple terms:mask-mode decides whether the mask uses transparency or brightness to reveal content.
π§© Basic Syntax
Syntax
mask-mode: alpha | luminance;β Can be applied to one or multiple mask layers
β Default value: alpha
π― What Each Value Means
| Value | How It Works | Best For |
|---|---|---|
| alpha | Uses mask image transparency:opaque = visible, transparent = hidden | PNGs, SVGs, shapes with transparency |
| luminance | Uses brightness:white = visible, black = hidden | Gradients, grayscale masks, soft fades |
π§ Important Difference
alpha cares about transparency.
luminance cares about brightness.
Note
π§ͺ Example 1 β mask-mode: alpha (Default)
alpha mask
.alpha-mask {
mask-image: url(star-mask.png); /* PNG with transparent background */
mask-mode: alpha;
}β Transparency in the PNG decides what is visible.
β Perfect for stencil shapes.
π§ͺ Example 2 β mask-mode: luminance
luminance mask
.light-mask {
mask-image: url(gradient-mask.jpg); /* grayscale gradient */
mask-mode: luminance;
}β White areas = fully visible
β Black areas = hidden
β Great for soft vignette fades and spotlight effects
π§ͺ Example 3 β Gradient Fade Using Luminance
fade with luminance
.fade {
mask-image: linear-gradient(to bottom, white, black);
mask-mode: luminance;
}β Smooth fading reveals based on brightness β ideal for text and images.
π¨ Multiple Masks with Different mask-mode
multiple mask modes
.multi-mask {
mask-image: url(mask1.png), radial-gradient(circle, white, black);
mask-mode: alpha, luminance;
}β First mask uses transparency
β Second uses brightness
β Useful for combining cut-out shapes + soft fades
π₯ Advanced Example β Glow Reveal Effect
glow reveal
.glow {
mask-image: radial-gradient(circle, white 30%, black 70%);
mask-mode: luminance;
mask-size: 150% 150%;
mask-position: center;
}β Produces a glowing reveal where brightness controls visibility
β Works beautifully with animations
π οΈ mask-mode + Animation
animated spotlight
@keyframes sweep {
to { mask-position: 100% 0; }
}
.spotlight {
mask-image: linear-gradient(90deg, black, white, black);
mask-mode: luminance;
mask-size: 200% 100%;
animation: sweep 2s infinite linear;
}β Creates a sliding spotlight reveal effect using brightness.
π οΈ Best Practices
- Use alpha for PNG/SVG icons with transparency
- Use luminance for gradient-based fades
- Use grayscale images for luminance masks
- Combine multiple mask layers for complex effects
- Test across browsers β mask rendering varies slightly
β οΈ Browser Support
- β Chrome
- β Safari
- β Edge
- β οΈ Firefox requires -webkit-mask-mode
Note
π Debugging Tips
- If mask disappears, ensure the mask image contains transparency or grayscale values
- If fades arenβt smooth, switch from alpha β luminance
- Check mask positioning with mask-position
- If mask is clipped, check mask-clip and mask-origin