CSS mask-border-mode Property

The CSS mask-border-mode property determines whether an image-based border mask uses alpha transparency or luminance to control an element's visibility.

It works with mask-border-source and the other mask border properties to determine how the source image is interpreted. The property accepts two values, alpha and luminance, but has limited browser support.

mask-border-mode Syntax

The mask-border-mode property accepts either alpha or luminance. CSS-wide keywords are also supported.

Basic Syntax

selector {
  mask-border-mode: alpha | luminance;
}

The vertical bar represents a choice between values. It is not included in an actual CSS declaration.

Alpha Masking

.element {
  mask-border-mode: alpha;
}

Luminance Masking

.element {
  mask-border-mode: luminance;
}

CSS-Wide Keywords

.element {
  mask-border-mode: initial;
}
.element {
  mask-border-mode: inherit;
}
.element {
  mask-border-mode: unset;
}
.element {
  mask-border-mode: revert;
}
.element {
  mask-border-mode: revert-layer;
}

The initial value is alpha.

Property Values

Value Description
alpha Uses the source image's alpha channel to determine the transparency of the mask border.
luminance Uses the source image's luminance and alpha channel to determine the transparency of the mask border.
initial Resets the property to its initial value of alpha.
inherit Inherits the computed value from the parent element.
unset Resets the property to alpha because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value alpha
Inherited No
Applies to All elements, with SVG-specific applicability rules
Computed value As specified
Animation type Discrete
Shorthand property mask-border
Browser availability Limited availability
Common use Controlling how source image colors and transparency affect border masking

How It Works

The mask-border-mode property determines how the browser converts a mask border source image into transparency values.

The browser first divides the source image according to mask-border-slice. It then uses the selected masking mode to determine how much of the element is revealed by the resulting mask.

Alpha Mode

In alpha mode, only the transparency of the source image matters. Opaque pixels reveal the element, while transparent pixels hide it.

Luminance Mode

In luminance mode, the brightness of each source pixel also matters. White reveals the element, black hides it, and gray produces partial transparency.

The Role of Alpha Transparency

Even in luminance mode, alpha transparency affects the result. A fully transparent pixel hides the element regardless of its color.

Important Consideration

The masking mode changes how the source image is interpreted. It does not change the source image itself or the dimensions of the element.

Alpha Masking

Alpha masking uses the source image's alpha channel to determine visibility. The source pixel's RGB color does not affect the masking strength.

Alpha Mask Example

.masked-panel {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-mode: alpha;
}

Opaque regions of the image reveal the element, while transparent regions hide it.

Opaque Black and White

In alpha mode, opaque black and opaque white pixels both produce full visibility.

Partially Transparent Pixels

A pixel with 50% alpha produces approximately 50% mask opacity, allowing the element to appear partially transparent.

Gradient Example

.masked-panel {
  mask-border-source: linear-gradient(to right, black, transparent);
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
  mask-border-mode: alpha;
}

The gradient transitions from fully opaque to transparent, producing a gradual masking effect.

Important Consideration

Use transparency, rather than black color alone, when creating hidden regions in an alpha mask.

Luminance Masking

Luminance masking uses the brightness of the source image's colors together with their alpha transparency.

White areas reveal the element, black areas hide it, and intermediate gray values produce partial visibility.

Luminance Mask Example

.masked-panel {
  mask-border-source: url("grayscale-border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-mode: luminance;
}

Black and White Gradient

.masked-panel {
  mask-border-source: linear-gradient(to right, white, black);
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
  mask-border-mode: luminance;
}

The white end reveals the element, while the black end hides it. The transition creates intermediate levels of transparency.

Gray Values

.masked-panel {
  mask-border-source: linear-gradient(to right, white, gray, black);
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
  mask-border-mode: luminance;
}

The gray portion produces partial visibility according to its calculated luminance.

Colored Pixels

Colors other than black, white, and gray can also be used. Their contribution is determined by their luminance rather than by a simple average of the red, green, and blue channels.

Important Consideration

Luminance masking is defined by the specification, but support for mask-border-mode: luminance is not reliable across major browsers.

Alpha vs. Luminance

The difference between the two modes is most noticeable when the source image contains opaque black, white, or gray pixels.

Source Pixel Alpha Mode Luminance Mode
Opaque white Fully visible Fully visible
Opaque black Fully visible Hidden
Opaque gray Fully visible Partially visible
Fully transparent Hidden Hidden
50% transparent white Approximately 50% visible Approximately 50% visible
50% transparent black Approximately 50% visible Hidden

Alpha Mode

.element {
  mask-border-mode: alpha;
}

Use alpha mode when the source image is designed with transparent and opaque regions.

Luminance Mode

.element {
  mask-border-mode: luminance;
}

Use luminance mode when the source image is designed with brightness values that should determine visibility.

Important Consideration

The two modes can produce very different results from the same image. A completely opaque black-and-white image remains fully visible in alpha mode but can produce a detailed mask in luminance mode.

Using the mask-border Shorthand

The mask-border-mode property is one of the six longhand properties represented by the mask-border shorthand.

Alpha Mode Shorthand

.element {
  mask-border: url("border-mask.png") 30 fill / 20px round alpha;
}

Luminance Mode Shorthand

.element {
  mask-border: url("border-mask.png") 30 fill / 20px round luminance;
}

Equivalent Longhand Declarations

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-outset: 0;
  mask-border-repeat: round;
  mask-border-mode: luminance;
}

Override the Shorthand

.element {
  mask-border: url("border-mask.png") 30 fill / 20px round alpha;
  mask-border-mode: luminance;
}

The later longhand declaration changes the masking mode to luminance.

Shorthand Reset

.element {
  mask-border-mode: luminance;
  mask-border: url("border-mask.png") 30 fill / 20px;
}

The later shorthand resets mask-border-mode to its initial value of alpha because no mode is specified.

Interaction with mask

.element {
  mask-border-mode: luminance;
  mask: linear-gradient(black, transparent);
}

The mask shorthand also resets the mask border properties, including mask-border-mode.

Important Consideration

Place mask-border-mode after the mask and mask-border shorthands when its value should override their reset behavior.

mask-border-mode Example

This example compares alpha and luminance masking using the same black-and-white gradient. Because the standardized mask-border-mode property has limited browser support, the Browser Result uses the more widely supported mask-mode property to demonstrate the difference between the two masking calculations.

HTML Example

<div class="mask-mode-demo">
  <div class="mask-mode-box mask-mode-alpha">Alpha Mask</div>
  <div class="mask-mode-box mask-mode-luminance">Luminance Mask</div>
</div>

CSS Example

.mask-mode-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
  padding: 15px;
  background-color: #f1f5f9;
}
.mask-mode-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  padding: 15px;
  background-color: #2563eb;
  color: #fff;
  font-weight: bold;
  text-align: center;
  mask-image: linear-gradient(to right, white, black);
}
.mask-mode-alpha {
  mask-mode: alpha;
}
.mask-mode-luminance {
  mask-mode: luminance;
}
Browser Result
Alpha Mask
Luminance Mask

In a browser supporting mask-mode, the alpha example remains fully visible because both gradient colors are opaque. The luminance example fades from visible white to hidden black.

This demonstrates the masking calculations used by mask-border-mode, but it does not demonstrate browser support for the mask border property itself.

Apply Alpha Mode to a Mask Border

.border-mask-alpha {
  mask-border-source: linear-gradient(to right, white, black);
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
  mask-border-mode: alpha;
}

Apply Luminance Mode to a Mask Border

.border-mask-luminance {
  mask-border-source: linear-gradient(to right, white, black);
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
  mask-border-mode: luminance;
}

These declarations show the standardized mask border syntax. They may not produce the intended visual result in browsers without support for mask-border-mode.

Change the Source Gradient

.border-mask-luminance {
  mask-border-source: linear-gradient(to bottom, white, gray, black);
}

In a supporting implementation, the gradient creates a luminance transition from visible to partially visible to hidden.

Return to Alpha Mode

.border-mask-luminance {
  mask-border-mode: alpha;
}

The source image is interpreted using its transparency rather than its brightness.

Common Mistakes

Expecting Opaque Black to Hide Content in Alpha Mode

Opaque black is fully visible in alpha mode. Use transparent pixels or luminance mode when black should represent hidden content.

Assuming Luminance Mode Is Widely Supported

The standardized mask-border-mode property has limited browser support. Do not rely on luminance-based mask borders without testing.

Confusing mask-border-mode with mask-mode

The mask-border-mode property controls mask border sources. The mask-mode property controls ordinary mask image layers.

Using an Invalid Value

.element {
  mask-border-mode: brightness;
}

The value brightness is invalid. Use alpha or luminance.

Expecting the Property to Create a Mask Border

.element {
  mask-border-mode: luminance;
}

This declaration alone does not create a mask border. A valid source image must also be supplied through mask-border-source or the shorthand.

Overwriting the Mode with a Shorthand

.element {
  mask-border-mode: luminance;
  mask-border: url("border-mask.png") 30 fill / 20px;
}

The later shorthand resets the mode to alpha.

Ignoring Alpha in Luminance Mode

A transparent white pixel does not reveal the element. Its alpha value is zero, so its masking contribution is also zero.

Expecting Masking to Change Layout

The property affects rendering and visibility, not the dimensions or document flow of the element.

Important Considerations

Keep the following points in mind when using mask-border-mode:

  • The property controls how a mask border source image is interpreted.
  • It accepts alpha and luminance.
  • The initial value is alpha.
  • The property is not inherited.
  • Alpha mode uses the source image's transparency.
  • Luminance mode uses the source image's brightness and transparency.
  • Opaque black and opaque white are equally visible in alpha mode.
  • Opaque black is hidden in luminance mode.
  • Opaque white is visible in luminance mode.
  • Gray pixels produce intermediate visibility in luminance mode.
  • Fully transparent pixels hide content in either mode.
  • Colored pixels contribute according to their luminance in luminance mode.
  • The property does not create a mask border without a source image.
  • It is a longhand component of the mask-border shorthand.
  • The mask-border shorthand resets omitted mode values to alpha.
  • The mask shorthand also resets mask border properties.
  • The property does not change element layout dimensions.
  • The standardized property has limited browser support.
  • The legacy -webkit-mask-box-image property does not provide an equivalent standardized mode control.
  • Use mask-mode when controlling ordinary CSS mask image layers.
  • Test the intended result across supported browsers before using it in production.

Browser Support

The CSS mask-border-mode property has Limited availability and is not part of Baseline because it is not consistently supported across major browsers.

Some browsers support mask borders through the legacy -webkit-mask-box-image property, but that does not provide equivalent support for selecting alpha or luminance mode with mask-border-mode.

For current compatibility information, visit Can I Use? and search for mask-border-mode.

When broad compatibility is required, consider ordinary CSS mask images or SVG masking techniques instead.

Specifications

The mask-border-mode property is defined in CSS Masking Module Level 1.

CSS Masking Module Level 1: mask-border-mode

The specification defines the two masking modes and how they determine the mask border's transparency values.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: mask-border-mode