CSS mask-mode Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The mask-mode property is set on the element being masked. It decides whether the mask-image is read as an alpha mask or a luminance mask.

It is not inherited. The initial value is match-source. You need a mask-image first — mask-mode alone does nothing.

Limited availability.

Not deprecated, but not Baseline Widely available. Safari 15.4+ support is partial (especially luminance). Prefer alpha when soft transparency from PNGs or gradients is enough.

CSS Syntax

syntax.css
mask-mode: alpha | luminance | match-source | initial | inherit;

Multiple comma-separated values map to multiple mask-image layers.

Property Values

ValueDescriptionTry it
alphaUse only the mask’s transparency (ignore color)Try it
luminanceUse brightness × alpha: white shows, black hidesTry it
match-sourceDefault. Images/gradients → alpha; SVG <mask> → luminanceTry it
initialResets to match-sourceTry it
inheritTakes the parent’s mask-modeTry it

How to Use mask-mode

Pick how the mask’s pixels should control visibility.

  1. Set mask-image (gradient, PNG, or SVG).
  2. Choose alpha for transparency-only masks (typical PNGs and fades).
  3. Choose luminance when black/white brightness should drive the cutout.
  4. Leave match-source when the source type should decide for you.
PieceRequired?Role
mask-imageYesProvides the mask layer to interpret
mask-modeOptionalOverrides how that layer is read
Opaque colors in the maskFor demosReveal alpha vs luminance differences clearly
SVG mask-typeSVG onlyUsed when match-source points at an SVG <mask>

Live Preview

Same colored mask (black → green → white). Switch the mode and watch visibility change.

Mask colors are fully opaque. Alpha keeps the whole strip; luminance dims by brightness.

Box
  • black
  • green
  • white

mask-mode: alpha — colors ignored; all opaque areas show

CSS Examples

Each snippet focuses on mask-mode. Use Try It Yourself for a live editor.

Example 1 — Alpha Mode

Ignore mask colors; use transparency only. Opaque colors all stay visible.

CSS
<style>
  div {
    width: 220px;
    height: 140px;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    mask-image: linear-gradient(to right, #000, #008000, #fff);
    mask-mode: alpha;
  }
</style>

<div></div>
Try It Yourself

How It Works

  1. Apply a mask. The gradient is black, green, and white — all opaque.
  2. Set alpha. Only transparency counts; hue is ignored.
  3. Result. The whole strip stays visible because nothing is transparent.
  4. Best for. PNG alpha cutouts and soft gradient fades.

Example 2 — Luminance Mode

Same mask, different reading: brightness now controls how much shows.

CSS
<style>
  div {
    width: 220px;
    height: 140px;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    mask-image: linear-gradient(to right, #000, #008000, #fff);
    mask-mode: luminance;
  }
</style>

<div></div>
Try It Yourself

How It Works

  1. Keep the same mask. Colors are still fully opaque.
  2. Switch to luminance. Visibility = brightness × alpha.
  3. Black hides. Green is partly visible (~36%). White is fully visible.
  4. Best for. Grayscale art and SVG <mask> fills.

Example 3 — Match-source (Default)

Let the mask source pick the mode. Gradients resolve to alpha.

CSS
<style>
  div {
    width: 220px;
    height: 140px;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    mask-image: linear-gradient(to right, #000, #008000, #fff);
    mask-mode: match-source;
  }
</style>

<div></div>
Try It Yourself

How It Works

  1. Default value. match-source is the initial setting.
  2. Gradient source. CSS images resolve to alpha, so this matches Example 1.
  3. SVG exception. An SVG <mask> defaults to luminance via its mask-type.
  4. Override anytime. Set alpha or luminance explicitly when you need a fixed rule.

Edge Cases & Pitfalls

Most confusion comes from opaque colors looking identical until luminance is on.

need

Needs mask-image

Without a mask layer, changing mask-mode has no visible effect.

alpha

Opaque colors look the same in alpha

Black, green, and white are all fully opaque. Only luminance treats them differently.

svg

SVG <mask> defaults to luminance

With match-source, SVG masks follow mask-type (default luminance). Set mask-mode: alpha to force transparency-only.

safari

Safari luminance is partial

Test luminance carefully in Safari. Prefer alpha masks when you need reliable cross-browser fades.

Browser Support

mask-mode is a browser CSS property. Node.js, Deno, and Bun do not apply it.

✓ Limited availability

mask-mode

Chrome 120+, Edge 120+, Firefox 53+, Opera 106+, Samsung Internet 25+. Safari 15.4+ has partial support. Internet Explorer has no support.

76% Full support reach
Google Chrome 120+
Full support
Mozilla Firefox 53+
Full support
Apple Safari 15.4+
Partial support
Microsoft Edge 120+
Full support
Opera 106+
Full support
Samsung Internet 25.0+
Full support
Internet Explorer No support
Not supported
mask-mode Limited / partial in Safari

Bottom line: Use with progressive enhancement. Prefer alpha for the widest reliable effect. Not a server runtime API.

Key Takeaways

  • Role: choose how mask-image is interpreted — alpha or luminance.
  • Values: alpha, luminance, match-source.
  • Initial value: match-source. Not inherited.
  • Tip: white shows, black hides — but only when luminance is active.

One line: mask-mode picks whether the mask listens to transparency only, or to brightness too.

Frequently Asked Questions

It tells the browser whether to read a mask as alpha (transparency only) or luminance (brightness × alpha). It is set on the element being masked.
The initial value is match-source. Image and gradient masks resolve to alpha; SVG <mask> sources default to luminance unless mask-type says otherwise.
Alpha ignores color and uses only transparency. Luminance also uses brightness: white shows, black hides, and mid colors partially show.
No. mask-mode only changes how an existing mask-image (or mask layer) is interpreted.
Use luminance for grayscale or colored masks where brightness should control visibility—especially SVG <mask> artwork.
Limited availability: Chrome 120+, Edge 120+, Firefox 53+, Opera 106+, Samsung Internet 25+. Safari 15.4+ has partial support (luminance can be unreliable). Internet Explorer does not support it. It is a browser CSS property, not a Node.js feature.

Next: mask-origin

Learn which box edge the mask is positioned from.

mask-origin tutorial →

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