CSS mask-mode Property

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
Visual Effects

What You’ll Learn

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.

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.

📝 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.

Basic Example

mask-mode.css
.mask-alpha {
  width: 300px;
  height: 200px;
  background: url('/images/valley-pattern.jpg') center/cover;
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-mode: alpha;
  mask-mode: alpha;
}

.mask-luminance {
  width: 300px;
  height: 200px;
  background: url('/images/valley-pattern.jpg') center/cover;
  -webkit-mask-image: url('/images/orange.png');
  mask-image: url('/images/orange.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-mode: luminance;
  mask-mode: luminance;
}

Syntax Rules

  • The initial value is match-source.
  • mask-mode only applies when a mask-image is set.
  • 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.

⚡ Quick Reference

QuestionAnswer
Initial valuematch-source
Applies toAll elements
InheritedNo
AnimatableNo
Common useChoosing alpha vs luminance interpretation for mask-image

💎 Property Values

The mask-mode property accepts three keyword values that control how the mask image is read.

ValueExampleMeaning
match-sourcemask-mode: match-source;Uses the alpha channel if the mask has one; otherwise uses luminance values.
alphamask-mode: alpha;Interprets the mask as an alpha mask using transparency to determine visibility.
luminancemask-mode: luminance;Interprets the mask as a luminance mask — lighter areas stay visible, darker areas are hidden.
initialmask-mode: initial;Resets to the default value (match-source)
inheritmask-mode: inherit;Inherits the mask mode from the parent element
match-source alpha luminance

🎯 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.

Alpha vs Luminance

ModeReads fromBest for
alphaTransparency channel of the mask imagePNG silhouettes, logos, and images with clear cutouts
luminanceBrightness of each mask pixelGrayscale photos, soft vignettes, and painted mask artwork
match-sourceAuto-detects alpha or luminanceEveryday use when you want sensible defaults

👀 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

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-mode.html
<style>
  .mask-alpha {
    width: 280px;
    height: 200px;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-mode: alpha;
    mask-mode: alpha;
  }
  .mask-luminance {
    width: 280px;
    height: 200px;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/orange.png');
    mask-image: url('/images/orange.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-mode: luminance;
    mask-mode: luminance;
  }
</style>

<div class="mask-alpha"></div>
<div class="mask-luminance"></div>
Try It Yourself

How It Works

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.

mask-mode-alpha.html
<style>
  .mask-alpha {
    width: 280px;
    height: 200px;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-mode: alpha;
    mask-mode: alpha;
  }
</style>

<div class="mask-alpha"></div>
Try It Yourself

How It Works

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.

mask-mode-luminance.html
<style>
  .mask-luminance {
    width: 280px;
    height: 200px;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/orange.png');
    mask-image: url('/images/orange.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-mode: luminance;
    mask-mode: luminance;
  }
</style>

<div class="mask-luminance"></div>
Try It Yourself

How It Works

Lighter areas in the mask image stay visible; darker areas fade out. This is ideal for grayscale artwork, photos, or hand-painted mask textures.

Example 4 — match-source (Default)

When you omit mask-mode, the browser uses match-source — alpha if the image has an alpha channel, otherwise luminance.

mask-mode-match.css
/* Default — no mask-mode needed */
.mask-default {
  background: url('/images/valley-pattern.jpg') center/cover;
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  /* mask-mode: match-source; — implicit default */
}
Try It Yourself

How It Works

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.

♿ Accessibility

  • Set mask-image firstmask-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.

Alpha vs Luminance

Featurealphaluminance
Reads fromAlpha (transparency) channelBrightness of each pixel
Best mask imagesPNG/SVG with clear transparencyGrayscale photos and painted textures
Soft edgesFrom partial transparency in the maskFrom gradual light-to-dark transitions
Typical useLogos, silhouettes, cutoutsVignettes, spotlight fades, photo masks

🧠 How mask-mode Works

1

You set a mask-image

Define the mask source with mask-image first.

Mask source
2

You choose a mask mode

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.

🖥 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 Chrome 55+ · Desktop & Mobile
Full support
Mozilla Firefox 54+ · Desktop & Mobile
Full support
Apple Safari 9.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 42+ · Modern versions
Full support
mask-mode property 90% supported

Bottom line: Safe for modern projects. Pair mask-mode with -webkit-mask-mode and test PNG masks in Safari.

🎉 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.

💡 Best Practices

✅ Do

  • 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

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
02

Luminance mode

Uses brightness.

Alternative
auto 03

match-source

Default auto mode.

Default
img 04

Needs mask-image

Requires a mask layer.

Dependency
web 05

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.

Practice in the Live Editor

Open the HTML editor, try mask-mode with alpha and luminance masks, and preview effects instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful