Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Filters, Masks and Shapes

The mask-repeat property

Reference for the CSS mask-repeat property: control whether a mask image tiles, using repeat, no-repeat, space and round, with live examples.

The mask-repeat property decides whether and how a mask image is tiled across the mask positioning area. The default is repeat, so a small mask image fills the whole element with copies. Set no-repeat to use the image once, which is what you want for a single shape or icon.

It uses the same keywords and behavior as background-repeat. Everywhere the mask is absent after tiling, the element is hidden, so the choice can reveal or hide large parts of the element.

CSS
.icon {
  mask-image: url(star.svg);
  mask-repeat: no-repeat;
}

Try it

Tiling modes compared

With space, whole tiles are spread with gaps and no scaling. With round, the tiles stretch or shrink so a whole number of them fits. The 140 by 110 pixel box does not divide evenly by 34 pixels, so the difference between the modes is visible.

Syntax

CSS
mask-repeat: <repeat-style>#

/* <repeat-style> = repeat-x | repeat-y
                  | [ repeat | space | round | no-repeat ]{1,2} */
  • Initial value: repeat
  • Applies to: all elements; in SVG, container elements (except <defs>) and graphics elements
  • Inherited: no
  • Animatable: no
  • Computed value: a list, each item a pair of keywords, one per dimension (repeat-x becomes repeat no-repeat, repeat-y becomes no-repeat repeat)

Values

Value Description
repeat Tiles in the given direction until the area is covered; the last tile may be cut off.
no-repeat Draws the image once.
repeat-x Shorthand for repeat no-repeat: tiles horizontally only.
repeat-y Shorthand for no-repeat repeat: tiles vertically only.
space Repeats whole tiles without clipping and distributes extra room as gaps.
round Repeats whole tiles, scaling them so they fit exactly.
Two values First value for the horizontal axis, second for the vertical axis, e.g. repeat space.

Usage notes

  • Default hides nothing, no-repeat hides a lot. With no-repeat, only the area covered by the single mask copy is visible, so combine it with a suitable mask-size and mask-position.
  • Gradient masks tile too. A linear-gradient mask with a smaller mask-size repeats like any image, so a fade can look like a repeated stripe.
  • space with a tile larger than the area shows only the first tile, as it cannot fit two.
  • round can distort. The tile is stretched in one dimension, so circles may become ellipses.
  • Each layer has its own value. Provide a comma-separated list when you have several mask images, otherwise the list repeats cyclically.
  • Shorthand reset. Using mask: ... resets mask-repeat to repeat unless you include a repeat keyword.

Browser support

Unprefixed mask-repeat works in current versions of the major browsers; older ones needed -webkit-mask-repeat.