π What Is mask-clip?
The mask-clip property defines which region of an element the mask is allowed to affect. In other words, it determines the clipping area where the mask is applied.
It works similarly to background-clip, but for masks. This helps you control whether the mask covers the border area, padding area, or only the content area.
π§© Basic Syntax
Syntax
mask-clip: border-box | padding-box | content-box | no-clip;β The value determines which region the mask is clipped to
β Each mask layer can have its own clip rule if multiple masks are used
π― Available Values
| Value | Area Affected | Description |
|---|---|---|
| border-box | Border + padding + content | Mask extends over the full element box |
| padding-box | Padding + content | Mask ignores border area |
| content-box | Only content | Mask clipped tightly to content area |
| no-clip | Mask not clipped at all | Mask can extend beyond element bounds |
Note
mask-clip determines how much area the mask can cover.
π§ͺ Example: mask-clip = border-box (Default)
border-box example
.box {
mask-image: url(mask.svg);
mask-clip: border-box;
}β Mask covers the entire element, including border, padding, and content.
π§ͺ Example: mask-clip = padding-box
padding-box example
.inner-mask {
border: 10px solid red;
padding: 30px;
mask-image: url(shape.png);
mask-clip: padding-box;
}β Mask is clipped inside the padding area
β Border is never affected by the mask
π§ͺ Example: mask-clip = content-box
content-box example
.content-mask {
padding: 40px;
mask-image: url(mask.png);
mask-clip: content-box;
}β Mask appears only on the inner content area
β Great for masking text or images inside padded boxes
π§ͺ Example: mask-clip = no-clip
no-clip example
.free-mask {
mask-image: radial-gradient(circle, white 60%, transparent);
mask-clip: no-clip;
}β Mask is not restricted by element bounds
β Can extend outward beyond padding & border
β Useful for glow or vignette-like effects
π¨ Combining mask-clip + mask-origin
mask-clip + mask-origin
.combo {
mask-image: url(shape.svg);
mask-origin: padding-box;
mask-clip: content-box;
}β Mask starts at padding-box
β But is clipped to content-box
β Great for precise masking zones
π Example: Multiple Masks with Different mask-clip
Multiple masks
.multi {
mask-image: url(mask1.png), url(mask2.png);
mask-clip: border-box, content-box;
}β First mask covers entire element
β Second mask covers only content
β Useful for layered stencil effects
π₯ Advanced Interaction: mask-clip + mask-size
Spotlight reveal
.spotlight {
mask-image: radial-gradient(circle, white 50%, transparent);
mask-size: 200px 200px;
mask-origin: content-box;
mask-clip: content-box;
}β Spotlight remains confined to content area
β Common in reveal animations and focused highlights
π οΈ Best Practices
- Use content-box for masking only inner content
- Use padding-box when you want borders to remain unaffected
- Use no-clip for dramatic visual effects that extend outward
- Pair with mask-origin for precise control
- Perfect for UI shine effects, cutouts, and creative patterns
β οΈ Browser Support
- β Chrome
- β Safari
- β Edge
- β οΈ Firefox requires -webkit-mask-clip
Note
π Debugging Tips
- If mask cuts off unexpectedly β check mask-clip
- If mask doesnβt align β adjust mask-origin or mask-size
- Use DevTools to visualize border/padding/content boxes
- Make sure mask image has transparency for visible effects