🧩 Mastering mask-composite in CSS

πŸ“Œ 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. 🎨✨

>>β€œmask-composite defines the math of how multiple masks interact β€” overlap, cut out, add, or exclude.”

🧩 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 ModeDescription
addBoth mask shapes are combined (union)
subtractThe top mask subtracts from the mask beneath
intersectOnly the overlapping region is visible
excludeEverything except their overlap is visible (XOR)

Note

mask-composite only works for multiple masks (comma-separated mask-image values).

πŸ§ͺ 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

For cross-browser support: βœ” Use both mask-composite and -moz-mask-composite.

πŸ› οΈ 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

mask-composite is powerful but inconsistent across browsers β€” always test your designs.

πŸ” 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

πŸ”— Helpful Resources

>>β€œmask-composite unlocks true graphic design power in CSS β€” blend, subtract, merge, and sculpt shapes freely.” ✨