CSS mask-composite Property

The CSS mask-composite property defines how multiple mask image layers are combined to determine which portions of an element remain visible.

It supports four compositing operations: add, subtract, intersect, and exclude. These operations combine the transparency of overlapping mask layers to create shapes, cutouts, intersections, and other masking effects without changing the underlying HTML.

mask-composite Syntax

The mask-composite property accepts one or more compositing keywords separated by commas. Each keyword specifies an operation used when combining mask layers.

Basic Syntax

selector {
  mask-composite: add;
}

Add

.element {
  mask-composite: add;
}

Subtract

.element {
  mask-composite: subtract;
}

Intersect

.element {
  mask-composite: intersect;
}

Exclude

.element {
  mask-composite: exclude;
}

Multiple Operations

.element {
  mask-composite: subtract, intersect;
}

CSS-Wide Keywords

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

The initial value is add, which combines mask layers using a union operation.

Property Values

Value Description
add Combines the source and destination mask layers so areas revealed by either layer remain visible.
subtract Keeps the source mask layer where it does not overlap the destination mask layer.
intersect Keeps only the areas where the source and destination mask layers overlap.
exclude Keeps areas belonging to either mask layer while removing their fully overlapping areas.
initial Resets the property to add.
inherit Inherits the computed value from the parent element.
unset Resets the property to add 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 add
Inherited No
Applies to All elements, with SVG-specific applicability rules
Computed value As specified
Animation type Discrete
Multiple values Yes, comma-separated
Shorthand property mask
Browser availability Baseline 2023 - Newly available

How It Works

Each CSS mask image produces transparency information that determines which parts of an element are visible. When multiple mask images are specified, mask-composite determines how their transparency values are combined.

The operations are based on compositing principles similar to Porter-Duff compositing. They operate on mask alpha values rather than simply comparing the colors of the images.

Step 1: Create the First Mask Layer

.element {
  mask-image: radial-gradient(circle at 35% 50%, black 30%, transparent 31%);
}

The first gradient creates a circular opaque region surrounded by transparency.

Step 2: Add Another Mask Layer

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
}

Two partially overlapping circles now provide the mask layers.

Step 3: Choose a Compositing Operation

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: intersect;
}

The intersect operation retains only the region where the two opaque circles overlap.

Step 4: Change the Operation

.element {
  mask-composite: exclude;
}

The exclude operation reveals the nonoverlapping portions of the two circles while removing their shared opaque area.

Source and Destination Layers

In the standardized model, the source is the current mask layer being processed, and the destination is the already-composited result of the layers beneath it.

The first mask image listed in mask-image is the topmost layer. Its compositing operation is applied against the layers below it.

Important Consideration

Mask compositing is performed in an isolated group. The element's background, underlying page content, and unrelated elements are not treated as additional destination mask layers.

add Value

The add value combines the visible areas of the source and destination mask layers. It is the initial value.

Basic Example

.element {
  mask-composite: add;
}

Two Circular Masks

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: add;
}

Both circles contribute to the visible region, including their overlapping area.

Union Operation

For fully opaque and fully transparent mask regions, add behaves like the union of two shapes. Any area included in either shape remains visible.

When to Use add

Use add to combine separate mask shapes into a larger visible region, such as overlapping circles, decorative cutouts, or multiple gradient regions.

Important Consideration

The add operation does not simply add opacity values without limits. It uses alpha compositing to produce a valid combined mask.

subtract Value

The subtract value retains the source mask layer while removing portions that overlap the destination mask layer.

Basic Example

.element {
  mask-composite: subtract;
}

Subtracting One Circle from Another

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: subtract;
}

The left circle is the source layer. Its overlapping area with the right circle is removed, leaving the portion of the left circle outside the right circle.

Reversing the Layers

.element {
  mask-image:
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%);
  mask-composite: subtract;
}

Reversing the image order changes the result because subtract is directional.

Creating a Cutout

.element {
  mask-image:
    linear-gradient(black, black),
    radial-gradient(circle at center, black 30%, transparent 31%);
  mask-composite: subtract;
}

The first mask covers the entire element. The second mask removes a circular area from that coverage, creating a transparent hole.

When to Use subtract

Use subtract to create holes, remove overlapping portions, or construct shapes with transparent interior regions.

Important Consideration

The order of mask images matters. Subtracting the destination from the source is not equivalent to subtracting the source from the destination.

intersect Value

The intersect value retains only areas where the source and destination mask layers overlap.

Basic Example

.element {
  mask-composite: intersect;
}

Overlapping Circular Masks

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: intersect;
}

Only the shared region between the two circles remains visible.

Combining a Gradient with a Shape

.element {
  mask-image:
    linear-gradient(to right, black, transparent),
    radial-gradient(circle, black 45%, transparent 46%);
  mask-composite: intersect;
}

The result is limited to the circular region, with its visibility further controlled by the horizontal gradient.

When to Use intersect

Use intersect when only the shared portions of multiple mask shapes should remain visible.

Important Consideration

If two fully opaque mask regions do not overlap, their intersection is transparent and the masked element may disappear.

exclude Value

The exclude value combines the nonoverlapping portions of the source and destination mask layers while removing their shared fully opaque region.

Basic Example

.element {
  mask-composite: exclude;
}

Overlapping Circular Masks

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: exclude;
}

The nonoverlapping portions of both circles remain visible, while their shared opaque region becomes transparent.

Creating a Ring

.element {
  mask-image:
    radial-gradient(circle, black 45%, transparent 46%),
    radial-gradient(circle, black 25%, transparent 26%);
  mask-composite: exclude;
}

The smaller circle is removed from the larger circle's opaque region, leaving a ring-shaped mask.

Difference from subtract

The subtract operation keeps only the source region outside the destination. The exclude operation keeps the nonoverlapping portions of both regions.

When to Use exclude

Use exclude for symmetrical cutouts, overlapping shapes with transparent intersections, and decorative masking effects.

Important Consideration

For partially transparent regions, the result is calculated from alpha values. The effect is not limited to a simple visible-or-hidden decision.

Comparing Compositing Operations

The four operations produce different results when two opaque mask shapes overlap.

Operation Source Only Overlap Destination Only
add Visible Visible Visible
subtract Visible Hidden Hidden
intersect Hidden Visible Hidden
exclude Visible Hidden Visible

Alpha Compositing Formulas

The operations can be expressed using source alpha (As) and destination alpha (Ad).

Operation Resulting Alpha
add As + Ad - As * Ad
subtract As * (1 - Ad)
intersect As * Ad
exclude As * (1 - Ad) + Ad * (1 - As)

These formulas explain how partially transparent masks are combined. The final alpha determines the visibility of the corresponding element pixels.

Choosing an Operation

Use add to combine visible areas, subtract to remove a destination shape from a source shape, intersect to retain shared areas, and exclude to retain nonoverlapping areas.

Multiple Mask Layers

The mask-composite property supports multiple comma-separated operations for elements with more than two mask image layers.

Three Mask Images

.element {
  mask-image:
    radial-gradient(circle at 25% 50%, black 20%, transparent 21%),
    radial-gradient(circle at 50% 50%, black 20%, transparent 21%),
    radial-gradient(circle at 75% 50%, black 20%, transparent 21%);
  mask-composite: add, exclude;
}

The first operation combines the topmost layer with the result of the layers beneath it. The second operation combines the next layer with the bottom layer.

Compositing Order

Mask images are listed from topmost to bottommost. Compositing is evaluated from the bottom of the stack toward the top.

For three layers, the second operation combines the middle and bottom layers first. The first operation then combines the top layer with that result.

One Operation for Multiple Layers

.element {
  mask-image:
    linear-gradient(black, transparent),
    radial-gradient(circle, black, transparent),
    linear-gradient(to right, black, transparent);
  mask-composite: intersect;
}

When fewer compositing values are supplied than mask layers, the values repeat to match the layer list.

More Operations Than Mask Layers

.element {
  mask-image:
    linear-gradient(black, transparent),
    radial-gradient(circle, black, transparent);
  mask-composite: subtract, intersect, exclude;
}

Only the operations corresponding to existing mask layers are considered. The compositing operation associated with the bottommost layer has no effect because there is no layer beneath it.

Interaction with mask-clip

.element {
  mask-image:
    linear-gradient(black, black),
    radial-gradient(circle, black 40%, transparent 41%);
  mask-clip: border-box, content-box;
  mask-composite: subtract;
}

Each mask layer is clipped according to its corresponding mask-clip value before the layers are combined.

Important Consideration

For predictable results, explicitly list the compositing operations when combining several different mask shapes.

Using the mask Shorthand

The mask-composite property is a longhand component of the mask shorthand.

Shorthand Example

.element {
  mask:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%) add,
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
}

The add keyword specifies the compositing operation associated with the first mask layer.

Equivalent Longhand Declarations

.element {
  mask-image:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: add;
}

Subtract in the Shorthand

.element {
  mask:
    linear-gradient(black, black) subtract,
    radial-gradient(circle, black 30%, transparent 31%);
}

The first mask layer is composited using subtract, creating a circular cutout.

Override the Shorthand

.element {
  mask:
    radial-gradient(circle at 35% 50%, black 30%, transparent 31%),
    radial-gradient(circle at 65% 50%, black 30%, transparent 31%);
  mask-composite: intersect;
}

The later longhand declaration changes the compositing operation to intersect.

Shorthand Reset Behavior

.element {
  mask-composite: subtract;
  mask:
    linear-gradient(black, black),
    radial-gradient(circle, black 30%, transparent 31%);
}

The later mask shorthand resets mask-composite to its initial value of add because no compositing keyword is included.

Correct Declaration Order

.element {
  mask:
    linear-gradient(black, black),
    radial-gradient(circle, black 30%, transparent 31%);
  mask-composite: subtract;
}

Place the longhand declaration after the shorthand when it should override the shorthand's compositing behavior.

mask-composite Example

This interactive-style comparison demonstrates all four mask-composite operations using two overlapping circular mask layers.

Each example uses identical mask images. Only the compositing operation changes, making the differences easy to compare.

HTML Example

<div class="mask-composite-demo">
  <div class="mask-composite-item">
    <div class="mask-composite-box composite-add"></div>
    <p>add</p>
  </div>
  <div class="mask-composite-item">
    <div class="mask-composite-box composite-subtract"></div>
    <p>subtract</p>
  </div>
  <div class="mask-composite-item">
    <div class="mask-composite-box composite-intersect"></div>
    <p>intersect</p>
  </div>
  <div class="mask-composite-item">
    <div class="mask-composite-box composite-exclude"></div>
    <p>exclude</p>
  </div>
</div>

CSS Example

.mask-composite-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  padding: 20px;
  background-color: #f1f5f9;
}
.mask-composite-item {
  min-width: 0;
  text-align: center;
}
.mask-composite-box {
  width: 100%;
  height: 120px;
  background-color: #2563eb;
  mask-image:
    radial-gradient(ellipse 45% 40% at 35% 50%, black 99%, transparent 100%),
    radial-gradient(ellipse 45% 40% at 65% 50%, black 99%, transparent 100%);
  mask-repeat: no-repeat;
}
.composite-add {
  mask-composite: add;
}
.composite-subtract {
  mask-composite: subtract;
}
.composite-intersect {
  mask-composite: intersect;
}
.composite-exclude {
  mask-composite: exclude;
}
.mask-composite-item p {
  margin: 10px 0 0;
  font-weight: bold;
}
@media (max-width: 575px) {
  .mask-composite-demo {
    grid-template-columns: 1fr;
  }
}
Browser Result

add

subtract

intersect

exclude

The add example shows the union of both circles. The subtract example retains the left circle outside the overlap. The intersect example shows only their shared region. The exclude example reveals the nonoverlapping portions of both circles.

Creating a Circular Cutout

.cutout-panel {
  width: 250px;
  height: 150px;
  background-color: #2563eb;
  mask-image:
    linear-gradient(black, black),
    radial-gradient(circle at center, black 35%, transparent 36%);
  mask-composite: subtract;
}

The opaque rectangular mask is the source, and the circular mask is the destination. The circle is subtracted from the rectangle, producing a transparent center.

Creating an Intersection

.intersection-panel {
  width: 250px;
  height: 150px;
  background-color: #059669;
  mask-image:
    linear-gradient(to right, black, transparent),
    radial-gradient(circle at center, black 45%, transparent 46%);
  mask-composite: intersect;
}

The result is a circular region whose opacity decreases according to the horizontal gradient.

Creating a Ring

.ring-panel {
  width: 200px;
  height: 200px;
  background-color: #2563eb;
  mask-image:
    radial-gradient(circle, black 45%, transparent 46%),
    radial-gradient(circle, black 25%, transparent 26%);
  mask-composite: exclude;
}

The inner circle is removed from the larger circle, producing a ring-shaped visible area.

Common Mistakes

Using Only One Mask Image

.element {
  mask-image: linear-gradient(black, transparent);
  mask-composite: subtract;
}

With only one mask layer, there is no second layer to combine. The compositing operation has no visible effect.

Confusing subtract with exclude

The subtract operation retains only the source outside the destination. The exclude operation retains nonoverlapping portions of both layers.

Using Unsupported Keywords

.element {
  mask-composite: multiply;
}

The standardized property does not accept multiply, screen, or overlay. Those are blending concepts associated with other CSS features.

Confusing mask-composite with mix-blend-mode

The mask-composite property combines mask transparency. The mix-blend-mode property controls how an element's colors blend with content behind it.

Assuming Layer Order Does Not Matter

Layer order is especially important for subtract. Reversing the source and destination can produce a different result.

Using Space-Separated Operations

.element {
  mask-composite: add subtract;
}

Multiple operations must be separated by commas.

Using an Invalid Number

.element {
  mask-composite: 2;
}

The property accepts compositing keywords, not numeric values.

Expecting Mask Colors to Blend

The property combines mask alpha values. It does not blend mask colors as ordinary image colors.

Overwriting the Property with the mask Shorthand

.element {
  mask-composite: intersect;
  mask:
    linear-gradient(black, transparent),
    radial-gradient(circle, black, transparent);
}

The later shorthand resets mask-composite to add.

Confusing Standard and Prefixed Syntax

The legacy -webkit-mask-composite property uses a different set of keywords and compositing conventions. Standardized mask-composite values should not be copied directly into the prefixed property.

Important Considerations

Keep the following points in mind when using mask-composite:

  • The property controls how multiple CSS mask layers are combined.
  • Its initial value is add.
  • The property is not inherited.
  • The add value combines visible regions.
  • The subtract value retains the source outside the destination.
  • The intersect value retains overlapping regions.
  • The exclude value retains nonoverlapping regions.
  • Compositing is based on mask alpha values.
  • Partially transparent mask regions are supported.
  • Multiple mask images are declared with comma-separated mask-image values.
  • Multiple compositing operations are separated by commas.
  • Mask images are ordered from topmost to bottommost.
  • Compositing is evaluated from the bottom layer toward the top.
  • The bottommost mask layer has no lower layer to composite against.
  • The order of mask layers matters for directional operations such as subtract.
  • When fewer operations are supplied than mask layers, the values repeat.
  • Extra operations beyond the number of mask layers have no effect.
  • The property is a longhand component of the mask shorthand.
  • The mask shorthand resets omitted compositing values to add.
  • The mask-clip property can restrict the area contributed by each mask layer.
  • The mask-origin property controls the positioning area of each mask image.
  • The mask-mode property determines how mask image values are interpreted.
  • Mask compositing changes visibility without changing the element's layout dimensions.
  • The legacy -webkit-mask-composite property uses different keywords.
  • Test complex mask effects in the browsers your website supports.

Browser Support

The CSS mask-composite property is Baseline 2023 - Newly available. The standardized property is supported in current versions of major browsers, although older browser versions may require alternative implementations.

Some older WebKit-based implementations provide related functionality through -webkit-mask-composite. That prefixed property uses different operation names, so its declarations are not interchangeable with the standardized property.

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

When supporting older browsers, test the actual masking result rather than relying only on whether the property is recognized.

Specifications

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

CSS Masking Module Level 1: mask-composite

The specification defines the four compositing operations, their alpha calculations, and how multiple mask layers are combined.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: mask-composite