The mask-composite property

The mask-composite property allows combining multiple masks applied to a single element. It determines how different masks will interact with each other when overlaid.

Syntax

cssselector {
  mask-composite: <compositing-operator>#;
}

Values

Value Description
add Result is the union of all masks (default).
subtract The second mask is subtracted from the first.
intersect Only the intersecting area of masks is displayed.
exclude Areas that are not common to both masks are displayed.

Example . Add mode

Combining two masks (heart and arrow):

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  mask-image: 
    url("heart.svg"),
    url("arrow.svg");
  mask-position: 
    100px 50px,
    200px 30px;
  mask-size: 150px;
  mask-repeat: no-repeat;
  mask-composite: add;
}

Результат:

Example . Subtract mode

Subtracting the arrow from the heart:

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  mask-image: 
    url("heart.svg"),
    url("arrow.svg");
  mask-position: 
    100px 50px,
    170px 80px;
  mask-size: 
    250px,
    120px;
  mask-repeat: no-repeat;
  mask-composite: subtract;
}

Результат:

Example . Intersect mode

Displaying only the intersection area of masks:

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  mask-image: 
    url("heart.svg"),
    url("arrow.svg");
  mask-position: 
    100px 50px,
    50px 30px;
  mask-size: 150px;
  mask-repeat: no-repeat;
  mask-composite: intersect;
}

Результат:

Example . Exclude mode

Displaying areas that are not common to both masks:

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  mask-image: 
    url("heart.svg"),
    url("arrow.svg");
  mask-position: 
    100px 50px,
    50px 30px;
  mask-size: 150px;
  mask-repeat: no-repeat;
  mask-composite: exclude;
}

Результат:

Example . Combination with gradients

Usage with gradient masks:

html<div id="gradient-box"></div>
css#gradient-box {
  width: 400px;
  height: 400px;
  background: linear-gradient(45deg, red, yellow, green, blue);
  mask-image: 
    radial-gradient(circle at 30% 30%, black 40%, transparent 70%),
    radial-gradient(circle at 70% 70%, black 40%, transparent 70%);
  mask-composite: exclude;
}

Результат:

See also

  • property mask-image,
    sets images for masks
  • property mask,
    shorthand for all masking properties
  • property mask-mode,
    defines the mask blending mode
  • property mix-blend-mode,
    defines the element blending mode