๐ What Is mask-origin?
The mask-origin property controls which box (border-box, padding-box, or content-box) is used as the reference area for positioning and sizing a mask image.
In simple terms:mask-origin decides where your mask is applied inside the element.
๐งฉ Basic Syntax
Syntax
mask-origin: border-box | padding-box | content-box;๐ฏ Understanding Each Value
| Value | Reference Area | Effect on Mask |
|---|---|---|
| border-box | Includes border + padding + content | Mask covers the whole element box |
| padding-box | Includes padding + content | Mask starts inside the border |
| content-box | Only content area | Mask clipped to content only |
Note
๐งช Example: border-box (Default)
border-box
.box {
mask-image: url(shape.png);
mask-origin: border-box;
mask-size: cover;
}โ Mask covers entire element including border area.
๐งช Example: padding-box
padding-box
.inner-mask {
padding: 20px;
mask-image: url(mask.png);
mask-origin: padding-box;
}โ Mask begins inside the border
โ Useful when border should appear outside the mask shape
๐งช Example: content-box
content-box
.content-only {
padding: 20px;
mask-image: url(mask.png);
mask-origin: content-box;
}โ Mask is applied only to the content area
โ Great for masking text or inner content without affecting padding/border
๐ Visual Comparison
| mask-origin value | Mask Area Affected |
|---|---|
| border-box | Mask covers border โ padding โ content |
| padding-box | Mask covers padding โ content |
| content-box | Mask only covers actual content |
๐จ mask-origin + mask-position
Position inside origin box
.highlight {
mask-image: url(circle.svg);
mask-origin: content-box;
mask-position: center;
}โ Mask is centered only within the content area, not the full element box.
๐ฅ Advanced Example: mask-origin + mask-clip
mask-origin + mask-clip
.clip-demo {
mask-image: url(shape.png);
mask-origin: padding-box;
mask-clip: content-box;
}โ Mask starts at padding-box
โ But is clipped to content-box
โ Produces precise mask regions
๐ง Using Multiple Masks with mask-origin
Multiple masks
.multi {
mask-image: url(mask1.png), url(mask2.png);
mask-origin: border-box, content-box;
}โ Each mask uses its own origin
โ Allows complex multi-layer masking layouts
๐ ๏ธ Best Practices
- Use border-box when mask should fill entire element
- Use padding-box when mask should ignore borders
- Use content-box when masking only main content
- Pair with mask-size and mask-position for best control
- Test across browsers for consistent rendering
โ ๏ธ Browser Support
- โ Chrome
- โ Safari
- โ Edge
- โ ๏ธ Firefox requires -webkit-mask-origin
Note
๐ Debugging Tips
- If mask seems misaligned โ check if origin box is correct
- If mask appears clipped โ inspect mask-clip settings
- Try changing mask-size to visualize how it scales inside the origin box
- Use DevTools to inspect element box model