π What Is mask-repeat?
The mask-repeat property controls how a mask image repeats across the elementβs box β similar to how background-repeat works for backgrounds.
It determines whether the mask image should repeat, stretch, or not repeat across the element.
π§© Syntax
Basic Syntax
mask-repeat: repeat | repeat-x | repeat-y | no-repeat | space | round;You can also define 2 values β mask-repeat: repeat no-repeat;
π― All mask-repeat Values Explained
| Value | Description |
|---|---|
| repeat | Repeats mask both horizontally & vertically |
| repeat-x | Repeats mask only horizontally |
| repeat-y | Repeats mask only vertically |
| no-repeat | No repetition (only one mask instance) |
| space | Adds equal space between repeated masks without cropping them |
| round | Scales mask so it fits perfectly an integer number of times |
π§ͺ Example: No Repeat
no-repeat example
.box {
mask-image: url(mask-star.png);
mask-repeat: no-repeat;
}β Only one star mask appears.
π§ͺ Example: Repeat Horizontally
repeat-x example
.banner {
mask-image: url(pattern.png);
mask-repeat: repeat-x;
}β Useful for horizontal decorative dividers.
π§ͺ Example: Repeat Vertically
repeat-y example
.sidebar {
mask-image: url(mask-gradient.png);
mask-repeat: repeat-y;
}β Creates vertical patterned masking.
π§ͺ Example: Full Repeat
repeat
.texture {
mask-image: url(texture-mask.png);
mask-repeat: repeat;
}β Great for texture-style reveals or mosaic effects.
π§ͺ Example: Space Mode
space example
.spaced {
mask-image: url(dot.png);
mask-repeat: space;
}β Even spacing between mask images
β No cropping β layout adjusts dynamically
π§ͺ Example: Round Mode
round example
.rounded-mask {
mask-image: url(tile.png);
mask-repeat: round;
}β The mask image is scaled so it fits perfectly an integer number of times.
β No leftover partial mask at edges.
π¨ Example: Combining mask-size + mask-repeat
Custom tiling
.pattern {
mask-image: url(icon.png);
mask-size: 40px;
mask-repeat: repeat;
}β Adjusts the mask tile size
β Helps build custom stencil patterns
π₯ Advanced Example: Multi-layer Mask
Multiple masks
.multi {
mask-image: url(shape1.png), url(shape2.png);
mask-repeat: repeat, no-repeat;
}β First mask repeats
β Second mask appears only once
π§ Best Practices
- Use no-repeat for logos or single shapes
- Use repeat for textures or patterns
- Use round to avoid awkward cropping
- Use space for symmetrical spacing effects
- Always pair with mask-size for perfect control
β οΈ Browser Support Notes
- β Chrome
- β Safari
- β Edge
- β οΈ Firefox (requires -webkit-mask-repeat)
Note
π Debugging Tips
- If mask disappears: check mask-image path
- If tiling looks wrong: adjust mask-size or mask-position
- Avoid large mask images when repeating β performance impact