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
selector {
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):
<img id="image" src="image.jpg">
#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:
<img id="image" src="image.jpg">
#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:
<img id="image" src="image.jpg">
#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:
<img id="image" src="image.jpg">
#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:
<div id="gradient-box"></div>
#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