π What Is mask-position?
The mask-position property controls where the mask image is placed inside the elementβs box β similar to how background-position works for backgrounds.
It defines the starting position of the mask relative to the element, allowing you to align masks precisely for creative cutouts, text reveals, sticker shapes, UI highlights, and more. π¨β¨
π§© Basic Syntax
Basic Syntax
mask-position: <position> | <x-pos> <y-pos>;
mask-position: center;
mask-position: left top;
mask-position: 20px 40px;
mask-position: 50% 50%;β You can use keywords, percentages, or length values
β Works similarly to background-position
π― Accepted Values
| Position Type | Examples | Description |
|---|---|---|
| Keywords | left, right, top, bottom, center | Aligns mask to a side or center |
| Percentages | 50% 50%, 0% 100% | Relative to element size |
| Lengths | 20px 40px | Exact pixel offset from the top-left corner |
π§ͺ Example: Position Mask in the Center
Center mask
.circle-cutout {
mask-image: url(circle.png);
mask-position: center;
mask-repeat: no-repeat;
}β The mask is perfectly centered over the element.
π§ͺ Example: Offset Mask to Top-Left
Top-left
.shape {
mask-image: url(shape.png);
mask-position: left top;
}β Great when aligning masks with decorative shapes.
π§ͺ Example: Exact Pixel Position
Pixel offset
.icon {
mask-image: url(star.svg);
mask-position: 10px 20px;
}β Useful for precise stencil placement.
π§ͺ Example: Center Horizontally, Bottom Vertically
center bottom
.fade {
mask-image: linear-gradient(to top, transparent, black);
mask-position: center bottom;
}β Perfect for fade-out overlays at top or bottom.
π Using Percentages
Percentage example
.spotlight {
mask-image: radial-gradient(circle, white 40%, transparent 60%);
mask-position: 70% 30%;
}β Moves the spotlight to the upper-right area β great for reveal effects.
π¨ Combining mask-position + mask-size
mask-size + mask-position
.pattern {
mask-image: url(tile.png);
mask-size: 50px 50px;
mask-position: 10px 10px;
mask-repeat: repeat;
}β Precise control for tiled mask patterns.
π₯ Example: Animated Mask Movement
Animated mask
@keyframes moveMask {
to { mask-position: 100% 0%; }
}
.moving {
mask-image: linear-gradient(90deg, transparent, white, transparent);
mask-size: 200% 100%;
animation: moveMask 3s infinite linear;
}β Creates a smooth scanning or shimmering effect.
π§ Multiple Masks with Different Positions
Multiple masks
.multi {
mask-image: url(mask1.png), url(mask2.png);
mask-position: 0 0, center;
}β First mask at top-left
β Second mask at center
β οΈ Browser Support
- β Chrome
- β Safari
- β Edge
- β οΈ Firefox: use -webkit-mask-position for compatibility
Note
π Debugging Tips
- If mask looks clipped β check mask-size
- If mask is repeating unexpectedly β set mask-repeat: no-repeat
- If alignment seems off β try changing mask-origin
- Use DevTools to inspect the mask visual box