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.
.icon { mask-image: url(star.svg); mask-repeat: no-repeat; }
Try it
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
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-xbecomesrepeat no-repeat,repeat-ybecomesno-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-repeathides a lot. Withno-repeat, only the area covered by the single mask copy is visible, so combine it with a suitablemask-sizeandmask-position. - Gradient masks tile too. A
linear-gradientmask with a smallermask-sizerepeats like any image, so a fade can look like a repeated stripe. spacewith a tile larger than the area shows only the first tile, as it cannot fit two.roundcan 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: ...resetsmask-repeattorepeatunless you include a repeat keyword.
Browser support
Unprefixed mask-repeat works in current versions of the major browsers; older ones needed -webkit-mask-repeat.
Related
maskโ the shorthandmask-imageโ the mask sourcemask-sizeโ how big each tile isbackground-repeatโ the same behavior for backgrounds- Lesson: Clip Paths and Masks