mask-composite

Mojtaba Seyedi on Updated on
##description##
Ad
`, } ); } })();

The mask-composite CSS property allows us to combine a mask layer image with the mask layers below it.

.element {
  mask-composite: subtract;
}

When there are multiple mask layer images, they need to be composited into one final mask layer. mask-compositespecifies how mask layers with different shapes are combined into a single image. Think of it like combining layers in an image editing app, like Photoshop, Figma or Sketch, where you have controls that set how the layers are combined.

Combining two layers in Sketch

Or, another way to think about it:

Circle plus rectangle equals a circle with the shape of a rectangle cut out of it.
The second layer (rectangle) is subtracted from the first layer (circle).

Syntax

mask-composite: <compositing-operator>#
where
<compositing-operator> = add | subtract | intersect | exclude

Values

/* Keyword values */
mask-composite: add;
mask-composite: subtract;
mask-composite: intersect;
mask-composite: exclude;

/* Global values */
mask-composite: inherit;
mask-composite: initial;
mask-composite: unset;

For the composition, the mask layer image that the mask-composite value is applied to is the source, while all mask layers below it are the destination.

Example

In the following example, two mask image layers are combined using exclude value:

img {
  mask-image: url(circle.svg), url(plus.svg);
  mask-size: 150px, 200px;
  mask-position: center;
  mask-composite: exclude;
}

At the time of writing, this example works only in Firefox.

Using multiple values

This property can take a comma-separated list of values for mask compositing and the number of values is one value less than the number of mask images specified using mask-image.

In the following example:

And so on for any number of mask layer images. Remember, the first image specified is placed on top of the ones specified after it.

.element {
  mask-image: url(circle.png), url(star.png), url(square.png);
  mask-composite: exclude, subtract;
}

Browser support

* Edge 18 supported mask-composite before adopting the Blink rendering engine.

More information