CSS mask-border-repeat Property

The CSS mask-border-repeat property controls how the edge regions of a mask border image are stretched, repeated, or spaced along an element's border.

It accepts one or two values using the keywords stretch, repeat, round, and space. These values determine how the sliced image fills the horizontal and vertical edges of the mask border area without changing the element's layout dimensions.

mask-border-repeat Syntax

The mask-border-repeat property accepts one or two repetition keywords. A single value applies to both directions, while two values allow different behavior along horizontal and vertical edges.

Basic Syntax

selector {
  mask-border-repeat: stretch | repeat | round | space;
}

The vertical bars indicate alternatives. They are not included in actual CSS declarations.

Stretch

.element {
  mask-border-repeat: stretch;
}

Repeat

.element {
  mask-border-repeat: repeat;
}

Round

.element {
  mask-border-repeat: round;
}

Space

.element {
  mask-border-repeat: space;
}

Two Values

.element {
  mask-border-repeat: round stretch;
}

CSS-Wide Keywords

.element {
  mask-border-repeat: initial;
}
.element {
  mask-border-repeat: inherit;
}
.element {
  mask-border-repeat: unset;
}
.element {
  mask-border-repeat: revert;
}
.element {
  mask-border-repeat: revert-layer;
}

The initial value is stretch, which stretches the edge regions to fill the available space.

Property Values

Value Description
stretch Stretches each edge slice to fill its corresponding mask border region.
repeat Repeats the edge slice to fill the available space, allowing partial repetitions at the ends.
round Repeats the edge slice and adjusts its size so a whole number of repetitions fits the available space.
space Repeats whole edge slices and distributes any remaining space between them. If only one repetition fits, it is centered.
initial Resets the property to stretch.
inherit Inherits the computed value from the parent element.
unset Resets the property to stretch 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 stretch
Inherited No
Applies to All elements, with SVG-specific applicability rules
Computed value One or two keywords, as specified
Animation type Discrete
Accepted values One or two repetition keywords
Shorthand property mask-border
Browser availability Limited availability

How It Works

A mask border image is divided into nine regions using mask-border-slice. These regions include four corners, four edges, and a center region.

The corner regions are positioned at the corners of the mask border area. The four edge regions fill the spaces between those corners according to the selected repetition values.

Nine-Slice Image

+--------------+--------------+--------------+
|   Top Left   |   Top Edge   |   Top Right  |
+--------------+--------------+--------------+
|   Left Edge  |    Center    |  Right Edge  |
+--------------+--------------+--------------+
|  Bottom Left |  Bottom Edge | Bottom Right |
+--------------+--------------+--------------+

The center region contributes to the mask only when fill is specified in mask-border-slice.

Edge Repetition

The top and bottom slices are arranged horizontally. The left and right slices are arranged vertically.

Basic Example

.masked-panel {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-repeat: round;
}

The source image is sliced into regions. The edge regions repeat along the sides, with their sizes adjusted to fit a whole number of repetitions.

Corner Behavior

The repetition property controls the edge regions, not the corner regions. Corners are positioned separately and are not tiled along the edges.

Important Consideration

The repetition behavior affects the mask border image, not the element's dimensions or position in document flow.

stretch Value

The stretch value stretches each edge slice to fill the available space between the corners.

Basic Example

.element {
  mask-border-repeat: stretch;
}

Complete Mask Border Example

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-repeat: stretch;
}

How Stretching Works

Each edge slice is resized to cover its entire corresponding edge region. The image is not repeated.

When to Use stretch

Stretching works well for smooth gradients, continuous shapes, and mask images that can be resized without noticeable distortion.

Potential Distortion

Patterns containing circles, dots, or other distinct shapes may become elongated when stretched across a wide or tall element.

Important Consideration

The stretch value is the default. It does not need to be declared unless you want to make the behavior explicit or override another value.

repeat Value

The repeat value tiles the edge slices along their corresponding sides without resizing them to fit an exact number of repetitions.

Basic Example

.element {
  mask-border-repeat: repeat;
}

Complete Mask Border Example

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-repeat: repeat;
}

How Repetition Works

The edge slice is repeated as many times as needed to fill the available region. Partial repetitions can appear at the ends.

Patterned Borders

Repeating is useful for masks containing dots, dashes, waves, or other decorative patterns designed to tile continuously.

Partial Repetitions

If the available space is not an exact multiple of the repeated image's size, the browser clips portions of the repetitions at the ends.

Important Consideration

Use a source image with seamless edge patterns when possible. Otherwise, visible joins may appear between repetitions.

round Value

The round value repeats the edge slices while adjusting their dimensions so a whole number of repetitions fits the available space.

Basic Example

.element {
  mask-border-repeat: round;
}

Complete Mask Border Example

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-repeat: round;
}

How Rounding Works

The browser determines an appropriate whole number of repetitions and adjusts their size so they fit the edge region without partial tiles.

Example

Suppose an edge region is 100 pixels long and a tile would normally occupy 30 pixels. The browser can fit approximately three repetitions, resizing them to about 33.3 pixels each.

Responsive Patterns

The round value is useful for patterned masks on elements whose dimensions change with the viewport.

Potential Resizing

Because tiles are resized to fit, their proportions or details may change slightly depending on the available space.

Important Consideration

Unlike repeat, the round value avoids partial repetitions by adjusting tile dimensions.

space Value

The space value repeats whole edge slices without resizing them, distributing remaining space between the repetitions.

Basic Example

.element {
  mask-border-repeat: space;
}

Complete Mask Border Example

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-repeat: space;
}

How Spacing Works

The browser places as many whole repetitions as possible and distributes the remaining space between them.

Single Repetition

If only one repetition fits, it is centered in the available edge region.

When to Use space

Spacing works well for patterns where preserving each repeated shape's dimensions is more important than keeping the shapes touching.

Potential Gaps

The spacing between repetitions can change as the element's dimensions change. This may create visible gaps in a continuous pattern.

Important Consideration

Unlike round, the space value preserves the tile dimensions rather than resizing them to fit.

One or Two Values

The mask-border-repeat property accepts one or two keywords to control the horizontal and vertical edges independently.

One Value

.element {
  mask-border-repeat: round;
}

The round value applies to all four edges.

Two Values

.element {
  mask-border-repeat: round stretch;
}

The first value controls the top and bottom edges. The second controls the left and right edges.

Repeat Horizontally and Stretch Vertically

.element {
  mask-border-repeat: repeat stretch;
}

Stretch Horizontally and Repeat Vertically

.element {
  mask-border-repeat: stretch repeat;
}

Round Horizontally and Space Vertically

.element {
  mask-border-repeat: round space;
}

Value Order Reference

Declaration Top and Bottom Left and Right
stretch Stretch Stretch
repeat Repeat Repeat
round stretch Round Stretch
repeat space Repeat Space
space round Space Round

Important Consideration

The values describe horizontal and vertical repetition behavior, not individual sides. Different behavior for the top and bottom edges cannot be specified independently with this property.

Using the mask-border Shorthand

The mask-border-repeat property is one of six longhand properties represented by the mask-border shorthand.

Shorthand Example

.element {
  mask-border: url("border-mask.png") 30 fill / 20px / 5px round alpha;
}

The round keyword specifies how the edge regions repeat.

Equivalent Longhand Declarations

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-outset: 5px;
  mask-border-repeat: round;
  mask-border-mode: alpha;
}

Two Repetition Values in the Shorthand

.element {
  mask-border: url("border-mask.png") 30 fill / 20px round stretch;
}

The top and bottom edges use round, while the left and right edges use stretch.

Override the Shorthand

.element {
  mask-border: url("border-mask.png") 30 fill / 20px stretch;
  mask-border-repeat: round;
}

The later longhand declaration changes the repetition behavior to round.

Shorthand Reset Behavior

.element {
  mask-border-repeat: repeat;
  mask-border: url("border-mask.png") 30 fill / 20px;
}

The later shorthand resets mask-border-repeat to stretch because no repetition value is included.

Interaction with mask

.element {
  mask-border-repeat: round;
  mask: linear-gradient(black, transparent);
}

The mask shorthand resets mask border properties, including mask-border-repeat.

Correct Declaration Order

.element {
  mask: linear-gradient(black, transparent);
  mask-border: url("border-mask.png") 30 fill / 20px;
  mask-border-repeat: round;
}

Declare mask border properties after the mask shorthand when their values must be preserved.

mask-border-repeat Example

This example compares the four repetition values using a decorative patterned border. Because standardized mask border support is limited, the Browser Result uses border-image-repeat to illustrate the same four edge repetition methods.

The demonstration uses a generated SVG image containing a circular pattern. The image is applied as a decorative border, making the differences visible in browsers that support border-image.

HTML Example

<div class="mask-repeat-demo">
  <div class="mask-repeat-box repeat-stretch">stretch</div>
  <div class="mask-repeat-box repeat-repeat">repeat</div>
  <div class="mask-repeat-box repeat-round">round</div>
  <div class="mask-repeat-box repeat-space">space</div>
</div>

CSS Example

.mask-repeat-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  padding: 15px;
  background-color: #f1f5f9;
}
.mask-repeat-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  padding: 15px;
  border: 20px solid transparent;
  background-color: #fff;
  color: #1e293b;
  font-weight: bold;
  text-align: center;
  border-image-source: url("pattern-border.svg");
  border-image-slice: 30;
  border-image-width: 20px;
}
.repeat-stretch {
  border-image-repeat: stretch;
}
.repeat-repeat {
  border-image-repeat: repeat;
}
.repeat-round {
  border-image-repeat: round;
}
.repeat-space {
  border-image-repeat: space;
}

The CSS above shows how an external SVG pattern can be used. The Browser Result below uses an embedded SVG data image so the demonstration does not require an external file.

Browser Result
stretch
repeat
round
space

The four examples demonstrate the differences between stretching, repeating, resizing to fit whole repetitions, and distributing space between repetitions.

This is a repetition demonstration, not a rendered mask border. The border-image-repeat property uses the same repetition keywords, but it paints decorative border artwork instead of masking the element.

Actual mask-border-repeat Declarations

.masked-stretch {
  mask-border: url("border-mask.png") 30 fill / 20px stretch;
}
.masked-repeat {
  mask-border: url("border-mask.png") 30 fill / 20px repeat;
}
.masked-round {
  mask-border: url("border-mask.png") 30 fill / 20px round;
}
.masked-space {
  mask-border: url("border-mask.png") 30 fill / 20px space;
}

These declarations use the standardized mask border shorthand. The source image must exist, and the browser must support the corresponding mask border features.

Use Different Repetition Methods

.masked-panel {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-repeat: round stretch;
}

The horizontal edges use round, while the vertical edges use stretch.

Switch to Repeating Tiles

.masked-panel {
  mask-border-repeat: repeat;
}

The edge regions use repeated tiles rather than stretched images.

Restore the Default

.masked-panel {
  mask-border-repeat: stretch;
}

The edge regions return to the default stretching behavior.

Common Mistakes

Expecting the Property to Create a Mask Border

.element {
  mask-border-repeat: round;
}

This declaration only specifies repetition behavior. A mask border source and appropriate slicing values are also needed.

Using Invalid Keywords

.element {
  mask-border-repeat: tile;
}

The value tile is invalid. Use stretch, repeat, round, or space.

Using Three or Four Values

.element {
  mask-border-repeat: repeat round stretch space;
}

The property accepts a maximum of two repetition keywords.

Confusing Horizontal and Vertical Order

.element {
  mask-border-repeat: round stretch;
}

The first value controls the top and bottom edges. The second controls the left and right edges.

Expecting round to Preserve Tile Dimensions

The round value adjusts tile dimensions to fit whole repetitions. Use repeat or space when preserving the tile size is more important.

Expecting space to Stretch Tiles

The space value distributes unused space between whole repetitions. It does not stretch tiles to eliminate gaps.

Ignoring Source Image Design

Repeated patterns may show visible seams when the source image is not designed to tile continuously.

Overwriting the Property with a Shorthand

.element {
  mask-border-repeat: round;
  mask-border: url("border-mask.png") 30 fill / 20px;
}

The later shorthand resets the repetition value to stretch.

Confusing mask-border-repeat with border-image-repeat

The properties use similar repetition rules, but mask-border-repeat controls a mask while border-image-repeat controls a painted border image.

Assuming Universal Browser Support

The standardized mask-border-repeat property has limited browser support. Test the intended effect before relying on it in production.

Important Considerations

Keep the following points in mind when using mask-border-repeat:

  • The property controls how mask border edge slices fill their regions.
  • Its initial value is stretch.
  • The property is not inherited.
  • It accepts one or two repetition keywords.
  • Valid keywords are stretch, repeat, round, and space.
  • A single keyword applies to both horizontal and vertical edges.
  • With two keywords, the first controls the top and bottom edges.
  • The second keyword controls the left and right edges.
  • The stretch value stretches each edge slice to fill its region.
  • The repeat value tiles the edge slices and may produce partial repetitions.
  • The round value adjusts tile dimensions to fit whole repetitions.
  • The space value distributes unused space between whole repetitions.
  • Corner slices are positioned separately from the repeated edge slices.
  • The center slice is controlled by the fill keyword in mask-border-slice.
  • The property does not create a mask border without a source image.
  • The source image should be designed for the selected repetition behavior.
  • Repeated patterns may show seams when the source image does not tile cleanly.
  • The property does not change the element's layout dimensions.
  • It is a longhand component of the mask-border shorthand.
  • The shorthand resets omitted repetition values to stretch.
  • The mask shorthand also resets mask border properties.
  • The standardized property has limited browser support.
  • The legacy -webkit-mask-box-image property provides related functionality in some browsers.
  • The legacy prefixed implementation is not identical to every standardized mask border feature.
  • Use a fallback when the visual effect is essential to the design.

Browser Support

The CSS mask-border-repeat property has Limited availability and is not part of Baseline because it is not consistently supported across major browsers.

Some browsers support related mask border functionality through the legacy -webkit-mask-box-image property, but this does not guarantee support for the standardized mask-border-repeat longhand.

For current compatibility information, visit Can I Use? and search for mask-border-repeat.

When broad compatibility is required, consider border-image-repeat for decorative borders or other supported masking techniques for transparency effects.

Specifications

The mask-border-repeat property is defined in CSS Masking Module Level 1.

CSS Masking Module Level 1: mask-border-repeat

The specification defines the accepted repetition keywords, their behavior, and how one or two values apply to the horizontal and vertical mask border edges.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: mask-border-repeat