CSS mask-repeat Property
The CSS mask-repeat property controls whether and how a mask image repeats across an element's mask positioning area.
It can display a mask image once, repeat it horizontally or vertically, or create a repeating pattern in both directions. The property also supports space and round, which adjust the spacing or size of repeated mask images to fit the available area.
mask-repeat Syntax
The mask-repeat property accepts a repetition keyword or two values that independently control horizontal and vertical repetition.
Basic Syntax
selector {
mask-repeat: repeat;
}
No Repetition
.element {
mask-repeat: no-repeat;
}
Horizontal Repetition
.element {
mask-repeat: repeat-x;
}
Vertical Repetition
.element {
mask-repeat: repeat-y;
}
Space Repetition
.element {
mask-repeat: space;
}
Round Repetition
.element {
mask-repeat: round;
}
Two-Value Syntax
.element {
mask-repeat: repeat no-repeat;
}
Multiple Mask Layers
.element {
mask-repeat: no-repeat, repeat;
}
CSS-Wide Keywords
.element {
mask-repeat: initial;
}
.element {
mask-repeat: inherit;
}
.element {
mask-repeat: unset;
}
.element {
mask-repeat: revert;
}
.element {
mask-repeat: revert-layer;
}
The initial value is repeat, which repeats the mask image horizontally and vertically.
Property Values
| Value | Description |
|---|---|
repeat |
Repeats the mask image in both directions, clipping partial repetitions at the edges. |
no-repeat |
Displays one copy of the mask image without repetition. |
repeat-x |
Repeats horizontally but not vertically. Equivalent to repeat no-repeat. |
repeat-y |
Repeats vertically but not horizontally. Equivalent to no-repeat repeat. |
space |
Repeats whole images with equal spacing when at least two copies fit. Does not resize them. |
round |
Repeats the image and adjusts its dimensions so a whole number of copies fits the positioning area. |
initial |
Resets the property to repeat. |
inherit |
Inherits the computed value from the parent element. |
unset |
Resets the property to repeat because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | repeat |
| Inherited | No |
| Applies to | All elements, with SVG-specific applicability rules |
| Computed value | Two keywords, one for each axis |
| Animation type | Discrete |
| Multiple values | Yes, comma-separated |
| Shorthand property | mask |
How It Works
The browser first determines the mask image's dimensions using mask-size, then positions the image using mask-position. The mask-repeat property determines whether additional copies are placed along either axis.
Step 1: Create an Element
<div class="masked-panel"></div>
Step 2: Add a Mask Image
.masked-panel {
width: 300px;
height: 150px;
background-color: #2563eb;
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 50px 50px;
}
The radial gradient defines a circular visible region inside a 50px by 50px mask tile.
Step 3: Repeat the Mask
.masked-panel {
mask-repeat: repeat;
}
The mask image repeats horizontally and vertically, creating a pattern of visible circles.
Step 4: Display One Mask
.masked-panel {
mask-repeat: no-repeat;
mask-position: center;
}
Only one circular mask appears, centered within the element.
Important Consideration
The mask image controls transparency, not the element's background pattern. Transparent areas of the mask hide the corresponding portions of the element and its contents.
repeat Value
The repeat value tiles the mask image horizontally and vertically. It is the default behavior.
Basic Example
.element {
mask-repeat: repeat;
}
Repeating Circular Masks
.element {
mask-image: radial-gradient(circle, black 40%, transparent 41%);
mask-size: 40px 40px;
mask-repeat: repeat;
}
The element displays a grid of circular visible regions.
Repeating Square Masks
.element {
mask-image: linear-gradient(black, black);
mask-size: 30px 30px;
mask-repeat: repeat;
}
Each mask tile is completely opaque, so the repeated tiles reveal the entire element without visible gaps.
When to Use repeat
Use repeat for regular mask patterns, such as dots, stripes, or decorative shapes that should extend across the available area.
Important Consideration
With repeat, partial tiles may be visible at the edges. The browser does not automatically resize tiles to make them fit evenly.
no-repeat Value
The no-repeat value displays a single mask image without creating additional copies.
Basic Example
.element {
mask-repeat: no-repeat;
}
Centered Circular Mask
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 120px 120px;
mask-position: center;
mask-repeat: no-repeat;
}
One circular region remains visible in the center of the element.
Mask in the Top-Right Corner
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 100px 100px;
mask-position: right top;
mask-repeat: no-repeat;
}
External Image Mask
.element {
mask-image: url("images/mask-shape.png");
mask-size: contain;
mask-position: center;
mask-repeat: no-repeat;
}
When to Use no-repeat
Use no-repeat for a single mask shape, spotlight, logo-shaped reveal, or image fade that should not tile.
Important Consideration
Areas outside the single mask image are transparent for that mask layer. If no other mask layers reveal those areas, the element will be hidden there.
repeat-x and repeat-y
The repeat-x and repeat-y keywords repeat a mask image along only one axis.
Horizontal Repetition
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 40px 40px;
mask-position: center;
mask-repeat: repeat-x;
}
The mask repeats horizontally, creating a single row of visible circles.
Vertical Repetition
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 40px 40px;
mask-position: center;
mask-repeat: repeat-y;
}
The mask repeats vertically, creating a single column of visible circles.
Equivalent Two-Value Syntax
.horizontal-mask {
mask-repeat: repeat no-repeat;
}
.vertical-mask {
mask-repeat: no-repeat repeat;
}
When to Use Single-Axis Repetition
Horizontal repetition works well for decorative borders and rows of shapes. Vertical repetition is useful for side patterns and repeating effects along the height of an element.
space Value
The space value repeats as many complete mask images as possible without clipping them, distributing any remaining space evenly between copies.
Basic Example
.element {
mask-repeat: space;
}
Spaced Circular Masks
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 55px 55px;
mask-repeat: space;
}
The browser fits whole mask tiles into the positioning area and distributes the extra space between them.
Horizontal Spacing Only
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 55px 55px;
mask-repeat: space no-repeat;
}
The mask images repeat with spacing horizontally but appear only once vertically.
When Only One Image Fits
If fewer than two mask tiles fit along an axis, the image is not repeated along that axis. Its placement follows mask-position.
When to Use space
Use space when repeated mask shapes should retain their dimensions and fit without partial tiles along the selected axis.
Important Consideration
The space value adjusts gaps between tiles, not their dimensions. If you need the tiles themselves to resize, use round.
round Value
The round value repeats mask images while adjusting their dimensions so that a whole number of copies fits the positioning area.
Basic Example
.element {
mask-repeat: round;
}
Rounded Repetition
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 55px 55px;
mask-repeat: round;
}
The browser adjusts the tile dimensions so that repeated copies fit the positioning area without being cut off at its edges.
Horizontal Round Repetition
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 55px 55px;
mask-repeat: round no-repeat;
}
Comparing round and repeat
.repeat-mask {
mask-repeat: repeat;
}
.round-mask {
mask-repeat: round;
}
The repeat value preserves the specified tile dimensions, even if partial tiles appear. The round value adjusts tile dimensions to fit whole repetitions.
When to Use round
Use round when a repeating mask pattern should fill its positioning area with complete tiles rather than clipped edges.
Important Consideration
Because round can resize mask tiles, their shapes or proportions may change. If one dimension is set to auto, the browser may adjust it to preserve the image's intrinsic aspect ratio according to the repetition rules.
Two-Value Syntax
The two-value syntax independently controls horizontal and vertical repetition. The first value applies horizontally and the second vertically.
| Value | Horizontal | Vertical |
|---|---|---|
repeat no-repeat |
Repeat | Do not repeat |
no-repeat repeat |
Do not repeat | Repeat |
space repeat |
Space | Repeat |
round no-repeat |
Round | Do not repeat |
repeat round |
Repeat | Round |
space round |
Space | Round |
Example
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 50px 50px;
mask-repeat: space no-repeat;
mask-position: center;
}
The mask repeats horizontally with evenly distributed spacing and remains a single row vertically.
Important Consideration
The repeat-x and repeat-y keywords are standalone shortcuts. They are not combined with a second repetition keyword.
Mask Size and Position
The mask-size and mask-position properties work with mask-repeat to determine the appearance of a repeating mask pattern.
Control Tile Dimensions
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 40px 40px;
mask-repeat: repeat;
}
Smaller mask tiles produce more repetitions within the same area.
Position a Repeating Row
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 50px 50px;
mask-position: center;
mask-repeat: repeat-x;
}
The repeating row is centered vertically.
Position a Single Mask
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 100px 100px;
mask-position: right bottom;
mask-repeat: no-repeat;
}
Change the Positioning Area
.element {
padding: 20px;
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-origin: content-box;
mask-size: 40px 40px;
mask-repeat: repeat;
}
The content box determines the positioning reference for the mask tiles.
Important Consideration
Mask images are repeated according to the mask positioning area, but mask-clip separately controls where each mask layer can affect the element.
Multiple Mask Layers
Each mask image layer can have its own repetition setting. Comma-separated values correspond to the layers defined by mask-image.
Two Mask Layers
.element {
mask-image:
radial-gradient(circle, black 45%, transparent 46%),
linear-gradient(to right, black, transparent);
mask-size: 50px 50px, 100% 100%;
mask-repeat: repeat, no-repeat;
}
The circular mask repeats while the linear gradient appears once.
Three Mask Layers
.element {
mask-image:
radial-gradient(circle, black 45%, transparent 46%),
linear-gradient(black, transparent),
radial-gradient(circle, black 45%, transparent 46%);
mask-size: 40px 40px, 100% 100%, 60px 60px;
mask-repeat: repeat-x, no-repeat, repeat-y;
}
Repeating Values
.element {
mask-image:
linear-gradient(black, transparent),
radial-gradient(circle, black, transparent),
linear-gradient(to right, black, transparent);
mask-repeat: no-repeat, repeat;
}
When fewer repetition values are supplied than mask layers, the values repeat. The third layer uses no-repeat.
Extra Values
.element {
mask-image:
linear-gradient(black, transparent),
radial-gradient(circle, black, transparent);
mask-repeat: repeat, no-repeat, round;
}
The third repetition value has no corresponding mask image layer and is not used for rendering.
Important Consideration
The mask-repeat property controls how each layer tiles. The mask-composite property controls how the resulting layers combine.
Using the mask Shorthand
The mask-repeat property is a longhand component of the mask shorthand.
Basic Shorthand
.element {
mask: url("images/mask-shape.png") center / contain no-repeat;
}
Repeating Mask
.element {
mask: radial-gradient(circle, black 45%, transparent 46%) 0 0 / 40px 40px repeat;
}
Equivalent Longhand Declarations
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-position: 0 0;
mask-size: 40px 40px;
mask-repeat: repeat;
}
Multiple Layers
.element {
mask:
radial-gradient(circle, black 45%, transparent 46%) 0 0 / 40px 40px repeat,
linear-gradient(black, transparent) center / 100% 100% no-repeat;
}
Override the Shorthand
.element {
mask: url("images/mask-shape.png") center / 80px 80px repeat;
mask-repeat: no-repeat;
}
The later longhand declaration overrides the repetition setting supplied by the shorthand.
Shorthand Reset Behavior
.element {
mask-repeat: no-repeat;
mask: url("images/mask-shape.png");
}
The later shorthand resets mask-repeat to its initial value of repeat.
mask-repeat Example
This example compares six repetition settings using the same circular gradient mask. Each box has identical dimensions and mask tile sizes.
HTML Example
<div class="mask-repeat-demo">
<div class="mask-repeat-item">
<div class="mask-repeat-box repeat-all"></div>
<p>repeat</p>
</div>
<div class="mask-repeat-item">
<div class="mask-repeat-box repeat-none"></div>
<p>no-repeat</p>
</div>
<div class="mask-repeat-item">
<div class="mask-repeat-box repeat-horizontal"></div>
<p>repeat-x</p>
</div>
<div class="mask-repeat-item">
<div class="mask-repeat-box repeat-vertical"></div>
<p>repeat-y</p>
</div>
<div class="mask-repeat-item">
<div class="mask-repeat-box repeat-space"></div>
<p>space</p>
</div>
<div class="mask-repeat-item">
<div class="mask-repeat-box repeat-round"></div>
<p>round</p>
</div>
</div>
CSS Example
.mask-repeat-demo {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.mask-repeat-item {
min-width: 0;
text-align: center;
}
.mask-repeat-box {
width: 100%;
height: 140px;
background-color: #2563eb;
mask-image: radial-gradient(circle, black 42%, transparent 43%);
mask-size: 55px 55px;
mask-position: center;
}
.repeat-all {
mask-repeat: repeat;
}
.repeat-none {
mask-repeat: no-repeat;
}
.repeat-horizontal {
mask-repeat: repeat-x;
}
.repeat-vertical {
mask-repeat: repeat-y;
}
.repeat-space {
mask-repeat: space;
}
.repeat-round {
mask-repeat: round;
}
.mask-repeat-item p {
margin: 10px 0 0;
font-weight: bold;
}
@media (max-width: 575px) {
.mask-repeat-demo {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
repeat
no-repeat
repeat-x
repeat-y
space
round
The repeat example tiles in both directions. The no-repeat example displays one circle. The repeat-x and repeat-y examples form a row and column. The space example distributes complete tiles with gaps, while round adjusts tile dimensions to fit.
Create a Horizontal Dot Pattern
.dot-border {
width: 300px;
height: 100px;
background-color: #059669;
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 30px 30px;
mask-position: center;
mask-repeat: repeat-x;
}
The element is revealed as a horizontal row of dots.
Create a Repeating Stripe Mask
.stripe-mask {
width: 300px;
height: 150px;
background-color: #2563eb;
mask-image: linear-gradient(to right, black 50%, transparent 50%);
mask-size: 40px 100%;
mask-repeat: repeat-x;
}
The repeated gradient creates alternating visible and transparent vertical stripes.
Common Mistakes
Forgetting the Default Repetition
.element {
mask-image: radial-gradient(circle, black 45%, transparent 46%);
mask-size: 80px 80px;
}
The mask repeats by default. Add mask-repeat: no-repeat when only one shape should appear.
Expecting mask-repeat to Create a Mask
.element {
mask-repeat: repeat-x;
}
The property does not create a mask image. Specify mask-image or use the mask shorthand.
Using an Invalid Keyword
.element {
mask-repeat: tile;
}
Use repeat instead of tile.
Using an Invalid Boolean Value
.element {
mask-repeat: false;
}
Use no-repeat to disable repetition.
Confusing space with round
The space value adjusts the gaps between tiles. The round value adjusts tile dimensions to fit whole repetitions.
Expecting mask-position to Move Spaced Tiles
When two or more tiles fit along an axis using space, their distribution is determined by the spacing rules. Positioning matters along that axis when only one tile fits.
Using an Incorrect Two-Value Combination
.element {
mask-repeat: repeat-x no-repeat;
}
The repeat-x keyword is a standalone shorthand for repeat no-repeat. Do not combine it with another repetition value.
Forgetting Mask Dimensions
A mask image that fills the positioning area may not show any visible repetition. Use mask-size to create smaller tiles when needed.
Overwriting the Property with mask
.element {
mask-repeat: no-repeat;
mask: url("images/mask-shape.png");
}
The later shorthand resets mask-repeat to its initial value of repeat.
Important Considerations
Keep the following points in mind when using mask-repeat:
- The property controls repetition of mask image layers.
- Its initial value is
repeat. - The property is not inherited.
repeattiles the mask image horizontally and vertically.no-repeatdisplays one copy of the mask image.repeat-xrepeats horizontally only.repeat-yrepeats vertically only.spacedistributes complete tiles without resizing them.roundadjusts tile dimensions to fit whole repetitions.- Two-value syntax independently controls horizontal and vertical repetition.
- The
mask-sizeproperty controls mask tile dimensions. - The
mask-positionproperty controls mask tile positioning. - The
mask-originproperty defines the positioning area. - The
mask-clipproperty controls the clipping area separately. - Multiple mask layers can use different repetition settings.
- Comma-separated values correspond to mask layers in order.
- Values repeat when fewer repetition settings are supplied than mask layers.
- The property does not create a mask image by itself.
- Repeated mask images affect visibility, not document layout.
- The property is a longhand component of the
maskshorthand. - The
maskshorthand resets omitted repetition settings torepeat. - SVG mask references use different masking rules from ordinary CSS image layers.
- Test complex repeating masks in the browsers your website supports.
Browser Support
The CSS mask-repeat property is Baseline 2023 - Newly available. It is supported in current versions of major browsers, including the common repeat, no-repeat, repeat-x, and repeat-y values.
Some older browsers require the -webkit-mask-repeat prefix. Support for space, round, and complex mask layer combinations may vary in older implementations.
For current compatibility information, visit Can I Use? and search for mask-repeat.
When supporting older browsers, test the actual repetition behavior, particularly with space, round, and multiple mask layers.
Specifications
The mask-repeat property is defined in CSS Masking Module Level 1.
CSS Masking Module Level 1: mask-repeat
The specification defines mask image repetition, single-axis repetition, spacing, and rounding behavior.
For additional documentation and examples, consult MDN Web Docs.
