CSS Portal

CSS mask-mode Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The mask-mode property controls how the pixel data of mask sources is interpreted when producing the coverage map that determines which parts of an element are revealed or obscured. In practice this means it decides whether the mask content is treated primarily as transparency information (how opaque each pixel is) or as a tonal/brightness map (how light or dark pixels contribute to coverage). That interpretation is applied to the source images, gradients, or other painting primitives that make up the mask before those results are used to affect the element’s rendering.

Because interpretation happens per source, choosing the mode changes not only the look of a single mask layer but also how multiple mask layers interact. Each layer’s pixels are converted into a coverage image according to the chosen mode, and those coverage images are then combined according to the compositing rules set elsewhere (for example, in mask-composite). The separation between “how to read a mask” and “how to combine masks” is important: a given bitmap may behave like a soft fade in one interpretation and like a hard punched shape in another, and that behavior will affect any composited result.

In real-world workflows, designers pick the interpretation that matches the source material and the intended visual effect. Photographic elements or images with actual alpha channels are naturally suited to an interpretation based on transparency, while hand-drawn grayscale maps and gradients are naturally interpreted as tonal coverage. The property therefore guides authoring decisions for the assets used in mask-image and related mask sources. When you need crisp geometric clipping rather than a gradual mask, consider alternate approaches such as clip-path or adjusting how a mask is authored with tools that match the intended interpretation (see also mask-type for other mask semantics).

Beyond visual appearance, the interpretation can affect rendering behavior: it influences interpolation and anti‑aliasing of mask pixels, how semi‑transparent pixels are treated during composition, and in some implementations can change performance characteristics because the rendering engine may take different compositing or sampling paths. Understanding what the mask source actually represents (alpha versus tonal information) helps avoid unwanted conversions, preserve edge fidelity, and produce predictable results when layering multiple masks.

Definition

Initial value
match-source
Applies to
all elements; In SVG, it applies to container elements excluding the <defs> element and all graphics elements
Inherited
no
Computed value
as specified
Animatable
yes
JavaScript syntax
object.style.maskMode

Syntax

mask-mode: <mode>;

Values

  • <mode>

    Where <mode> can be one of the following possible values:

    • match-source – The mask type is determined automatically from the image source.
    • luminance – Uses the luminance (brightness) of the mask image to define visibility; brighter areas are more visible.
    • alpha – Uses the alpha channel of the mask image to define visibility; fully opaque areas are fully visible, fully transparent areas are hidden.

Example

<div class='wrap'>
<h1>mask-mode: alpha vs luminance</h1>
<div class='examples'>
<div class='example alpha'>
<div class='label'>mask-mode: alpha</div>
</div>
<div class='example luminance'>
<div class='label'>mask-mode: luminance</div>
</div>
</div>
</div>
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  background: linear-gradient(135deg, #f6f8ff, #e8f0ff);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
}
.wrap {
  text-align: center;
}
.examples {
  display: flex;
  gap: 24px;
  margin-top: 18px;
  justify-content: center;
}
.example {
  width: 240px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(20,30,60,0.12);
  background-image: linear-gradient(135deg, #ff8a00, #e52e71);
}
.label {
  mix-blend-mode: difference;
  font-size: 16px;
}

/* shared mask image: contains shapes with identical alpha (0.5) but different colors */
.example {
  -webkit-mask-image: url('data:image/svg+xml;utf8,');
  -webkit-mask-size: cover;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-image: url('data:image/svg+xml;utf8,');
  mask-size: cover;
  mask-repeat: no-repeat;
  mask-position: center;
}

/* different mask-mode values */
.example.alpha {
  -webkit-mask-mode: alpha;
  mask-mode: alpha;
}
.example.luminance {
  -webkit-mask-mode: luminance;
  mask-mode: luminance;
}

/* small responsive */
@media (max-width: 520px) {
  .examples { flex-direction: column; gap: 12px; }
}

Browser Support

The following information will show you the current browser support for the CSS mask-mode property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!