π What Is mask-composite?
The mask-composite property controls how multiple mask layers combineto create a final masking shape.
When you apply more than one mask-image, they stack β and mask-compositedefines whether they intersect, subtract, add, or exclude each other.
This is similar to path operations in Illustrator or boolean operations in Figma. π¨β¨
π§© Basic Syntax
Syntax
mask-composite: add | subtract | intersect | exclude;β Applies when you use multiple mask layers
β Each composite value applies between corresponding mask layers
π― What Each Value Means
| Composite Mode | Description |
|---|---|
| add | Both mask shapes are combined (union) |
| subtract | The top mask subtracts from the mask beneath |
| intersect | Only the overlapping region is visible |
| exclude | Everything except their overlap is visible (XOR) |
Note
π§ͺ Example: Add (Union)
add example
.shape {
mask-image: url(circle-mask.png), url(square-mask.png);
mask-composite: add;
}β The circle + square become one combined mask shape
β Great for merging shapes or creating organic blobs
π§ͺ Example: Subtract
subtract example
.cutout {
mask-image: url(big-circle.png), url(small-circle.png);
mask-composite: subtract;
}β The small circle cuts a hole inside the big circle
β Perfect for donut/ring shapes or UI cutouts
π§ͺ Example: Intersect
intersect example
.intersection {
mask-image: url(circle.png), url(triangle.png);
mask-composite: intersect;
}β Only the overlapping area is visible
β Useful for spotlight or focused reveal effects
π§ͺ Example: Exclude (XOR)
exclude example
.xor-mask {
mask-image: url(mask1.png), url(mask2.png);
mask-composite: exclude;
}β Their overlapping region becomes transparent
β Great for artistic or glitch-style effects
π Advanced Example: Multiple Composites
Multiple masks
.multi {
mask-image: url(circle.png), url(rect.png), url(star.png);
mask-composite: add, subtract;
}β circle + rectangle β union
β result β star β cutout
β Enables complex stencil designs
π¨ Example: Creating a Donut Mask
Donut mask
.donut {
mask-image: url(outer-circle.png), url(inner-circle.png);
mask-size: contain;
mask-repeat: no-repeat;
mask-composite: subtract;
}
β Inner circle subtracts from outer β perfect ring shape
π₯ Example: Letter Cutout Mask
Text-cutout
.cut-text {
mask-image: url(rect.png), url(text-mask.png);
mask-composite: subtract;
}β Text removes itself from the rectangle mask
β Creates a classic βtext knockoutβ effect
β οΈ Vendor Prefixing
Firefox uses a different syntax:
Firefox composite
mask-composite: add;
-moz-mask-composite: add;Note
π οΈ Best Practices
- Use add to merge multiple shapes into one mask
- Use subtract to create cutout shapes or donuts
- Use intersect for spotlight or focused reveals
- Use exclude for artistic and abstract mask effects
- Always pair with mask-position and mask-size for precision
β οΈ Browser Support
- β Chrome
- β Safari
- β Edge
- β οΈ Firefox: requires -moz-mask-composite
Note
π Debugging Tips
- Ensure mask images have transparency or proper alpha channels
- If results look inverted, swap mask layer order
- Use DevTools to inspect mask layers (Chrome supports mask debugging)
- Start simple β add more layers gradually