The mask-mode property controls how a mask-image is interpreted — using its alpha channel, its luminance values, or matching the source automatically.
01
Alpha Mode
Mask by transparency.
02
Luminance Mode
Mask by brightness.
03
match-source
Default auto mode.
04
With mask-image
Requires a mask layer.
05
WebKit
Prefix for Safari.
06
Related
mask-size, origin.
Fundamentals
Introduction
The mask-mode property in CSS defines how the mask image is applied to an element. Masks can hide or reveal portions of an element, and mask-mode determines whether the alpha channel or the luminance channel of the mask image controls visibility.
This property is particularly useful for creating complex visual effects by selectively displaying or hiding parts of an element based on the mask. Pair it with mask-image to choose the mask source first, then use mask-mode to decide how that source is read.
Definition and Usage
Use mask-mode: alpha when your mask PNG or SVG has meaningful transparency. Use mask-mode: luminance when you want lighter pixels to stay visible and darker pixels to hide content — common with grayscale photos or illustrations. Leave it at the default match-source when you want the browser to pick the best interpretation automatically.
💡
Beginner Tip
Start with the same background and two different mask images side by side — one with clear transparency (alpha) and one grayscale image (luminance) — to see how the mode changes the result.
Foundation
📝 Syntax
The syntax for the mask-mode property uses one of three keyword values:
syntax.css
element{mask-mode:mode;}
Here, mode can be one of the specified keywords: match-source, alpha, or luminance.
alpha reads transparency from the mask image’s alpha channel.
luminance uses brightness — lighter areas stay visible, darker areas are hidden.
Include -webkit-mask-mode alongside mask-mode for broader Safari support.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
match-source
Applies to
All elements
Inherited
No
Animatable
No
Common use
Choosing alpha vs luminance interpretation for mask-image
Reference
💎 Property Values
The mask-mode property accepts three keyword values that control how the mask image is read.
Value
Example
Meaning
match-source
mask-mode: match-source;
Uses the alpha channel if the mask has one; otherwise uses luminance values.
alpha
mask-mode: alpha;
Interprets the mask as an alpha mask using transparency to determine visibility.
luminance
mask-mode: luminance;
Interprets the mask as a luminance mask — lighter areas stay visible, darker areas are hidden.
initial
mask-mode: initial;
Resets to the default value (match-source)
inherit
mask-mode: inherit;
Inherits the mask mode from the parent element
match-sourcealphaluminance
Default
🎯 Default Value
The default value of the mask-mode property is match-source, which means the mask mode will match the source image type. If the mask image has an alpha channel, alpha is used; otherwise the browser falls back to luminance.
Modes
Alpha vs Luminance
Mode
Reads from
Best for
alpha
Transparency channel of the mask image
PNG silhouettes, logos, and images with clear cutouts
luminance
Brightness of each mask pixel
Grayscale photos, soft vignettes, and painted mask artwork
match-source
Auto-detects alpha or luminance
Everyday use when you want sensible defaults
Preview
👀 Live Preview
The same gradient fill with two mask modes — alpha on a PNG silhouette and luminance on a grayscale image:
mask-mode: alpha
mask-mode: luminance
Hands-On
Examples Gallery
Compare alpha and luminance mask modes side by side, then explore each mode individually and the default match-source behavior.
🖼 Mask Modes
Start with the reference example — apply different mask-mode values to see how the same background responds.
Example 1 — Alpha vs Luminance
Use a mask image and apply different mask-mode values to demonstrate their effects side by side.
mask-alpha uses the alpha channel of the PNG to determine transparency, while mask-luminance uses the lightness values of the mask image. The same background looks different depending on which channel drives visibility.
Example 2 — Alpha Mask Mode
Set mask-mode: alpha when your mask image has a clear transparency channel — typical for PNG silhouettes and logos.
Opaque pixels in the mask keep the background visible; fully transparent pixels hide it. Semi-transparent areas create soft edges when the PNG supports partial alpha.
🛠 Luminance & Default
Explore brightness-based masking and the automatic match-source behavior.
Example 3 — Luminance Mask Mode
Use mask-mode: luminance when brightness — not transparency — should control what stays visible.
For most PNG masks with transparency, match-source behaves like alpha. For images without alpha, it falls back to luminance — so you often do not need to set this property explicitly.
A11y
♿ Accessibility
Set mask-image first — mask-mode has no effect without an active mask layer.
Do not hide essential content — Masked-away text or controls may be invisible but still exist in the DOM.
Test both modes — If a mask looks wrong, try switching between alpha and luminance.
Check contrast — Partially masked areas can reduce readability if text sits over them.
Offer fallbacks — Ensure content remains usable when masking is unsupported.
Pick alpha, luminance, or leave the default match-source.
Mode selection
3
Browser reads the chosen channel
Alpha mode uses transparency; luminance mode uses pixel brightness to control visibility.
Channel mapping
=
🖼
Targeted visibility effect
Only the parts of your element that match the mask channel stay visible.
Compatibility
🖥 Browser Compatibility
The mask-mode property is supported in most modern browsers, including Chrome, Firefox, Safari, and Edge. Include -webkit-mask-mode for Safari, and test alpha vs luminance with your actual mask images.
✓ Baseline · Modern browsers
Mask modes in modern browsers
Alpha and luminance modes work in all major browsers. Use the WebKit prefix for best Safari coverage.
95%Modern browser support
Google Chrome55+ · Desktop & Mobile
Full support
Mozilla Firefox54+ · Desktop & Mobile
Full support
Apple Safari9.1+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Opera42+ · Modern versions
Full support
mask-mode property90% supported
Bottom line: Safe for modern projects. Pair mask-mode with -webkit-mask-mode and test PNG masks in Safari.
Wrap Up
🎉 Conclusion
The mask-mode property is a versatile tool in CSS that lets you control how mask images affect the visibility of elements on your web page.
By choosing between alpha and luminance masks, you can create a wide range of visual effects that enhance the overall design of your site. Experiment with different mask images and modes to see how this property can add depth and interest to your web projects.
Use alpha for PNG silhouettes and logos with transparency
Use luminance for grayscale photos and brightness-based masks
Leave match-source as the default when unsure
Always set mask-image before applying mask-mode
Include -webkit-mask-mode alongside mask-mode
❌ Don’t
Set mask-mode without a mask-image
Assume alpha and luminance produce the same result on every image
Hide essential text or controls with masks
Forget WebKit prefixes when targeting Safari users
Skip testing when a mask looks unexpectedly wrong
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about mask-mode
Use these points when choosing how a mask image is interpreted.
5
Core concepts
🖼01
Alpha mode
Uses transparency.
Purpose
⚙02
Luminance mode
Uses brightness.
Alternative
auto03
match-source
Default auto mode.
Default
img04
Needs mask-image
Requires a mask layer.
Dependency
web05
WebKit prefix
Safari support.
Compat
❓ Frequently Asked Questions
The mask-mode property defines how a mask image is interpreted — using its alpha channel, its luminance values, or matching the source type automatically.
The default value is match-source, which uses the alpha channel when available, otherwise falls back to luminance.
Alpha mode uses transparency from the mask image. Luminance mode uses brightness — lighter areas stay visible, darker areas are hidden.
No. mask-mode only affects how an existing mask-image is applied. You must set mask-image first.
Use luminance when the mask is a grayscale image without meaningful alpha, or when you want brightness to control visibility.