πŸ” Mastering mask-repeat in CSS

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

>>β€œmask-repeat defines how your stencil (mask) tiles β€” giving you full creative control.”

🧩 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

ValueDescription
repeatRepeats mask both horizontally & vertically
repeat-xRepeats mask only horizontally
repeat-yRepeats mask only vertically
no-repeatNo repetition (only one mask instance)
spaceAdds equal space between repeated masks without cropping them
roundScales 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

For best compatibility, include both mask-repeat and -webkit-mask-repeat.

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

πŸ”— Helpful Resources

>>β€œmask-repeat lets your mask behave like a pattern β€” tile it, stretch it, space it, shape it.” 🎭✨