CSS border-image-repeat Property
The border-image-repeat property controls how the edge sections of a border image are stretched or repeated to fill an element's border.
It accepts the keywords stretch, repeat, round, and space. One value applies to all four edges, while two values allow different behavior for horizontal and vertical edges. The property is especially useful for decorative frames, repeating patterns, and image-based borders.
border-image-repeat Syntax
selector {
border-image-repeat: stretch;
}
The property accepts one or two keywords that determine how the sliced border image fills the available edges.
Single Value
.frame {
border-image-repeat: round;
}
The same repeat behavior applies to both horizontal and vertical edges.
Two Values
.frame {
border-image-repeat: round stretch;
}
The first value controls the top and bottom edges. The second controls the left and right edges.
Complete Border Image Example
.frame {
border: 20px solid transparent;
border-image-source: url("border-pattern.png");
border-image-slice: 30;
border-image-repeat: round;
}
The border image is divided into sections, and its edge sections repeat with adjusted tile sizes to fit the available space.
CSS-Wide Keywords
.inherited {
border-image-repeat: inherit;
}
.reset {
border-image-repeat: initial;
}
.unset {
border-image-repeat: unset;
}
.reverted {
border-image-repeat: revert;
}
.layer-reverted {
border-image-repeat: revert-layer;
}
CSS-wide keywords must be used alone and cannot be combined with repeat keywords.
Property Values
| Value | Description |
|---|---|
stretch |
Stretches each edge image section to fill the available border-image edge region. |
repeat |
Repeats each edge image section as tiles. Partial tiles may be clipped at the ends. |
round |
Repeats the edge image section and adjusts tile sizes so a whole number of tiles fits. |
space |
Repeats whole tiles and distributes leftover space between them. If two tiles cannot fit, one tile is centered. |
| One keyword | Applies the same repeat mode to horizontal and vertical edges. |
| Two keywords | Sets the horizontal repeat mode first and vertical repeat mode second. |
CSS-Wide Keywords
| Keyword | Behavior |
|---|---|
inherit |
Uses the parent's computed repeat values. |
initial |
Resets both repeat directions to stretch. |
unset |
Resets both directions to stretch because the property is not inherited. |
revert |
Reverts the value according to cascade origin rules. |
revert-layer |
Reverts the value according to cascade layer rules. |
The initial value is stretch. The property is not inherited and is not animatable.
How It Works
When a border image is applied, the source image is divided into nine sections using border-image-slice.
The four corner sections are placed at the element's corners. The four edge sections are then fitted along the top, right, bottom, and left edges.
The border-image-repeat property determines how those edge sections fill the available space.
Nine-Slice Image Structure
| Top-left corner | Top edge | Top-right corner |
| Left edge | Center | Right edge |
| Bottom-left corner | Bottom edge | Bottom-right corner |
Corner Sections
The corner sections are scaled into the corresponding border-image corner regions. They are not tiled by border-image-repeat.
Edge Sections
The top and bottom edge sections are fitted horizontally. The left and right edge sections are fitted vertically.
Center Section
The center section is normally discarded. If fill is specified in border-image-slice, the center is painted as well.
Basic Example
.frame {
border: 16px solid transparent;
border-image-source: url("decorative-border.png");
border-image-slice: 24;
border-image-repeat: repeat;
}
The source image is sliced 24 image units inward from each side. The resulting edge sections repeat along the border.
Changing Only the Repeat Mode
.frame {
border-image-repeat: round;
}
The source and slice remain unchanged. Only the way the edge sections fit into the available space changes.
The repeat mode affects border-image painting, not the element's content size or border-box dimensions.
stretch Value
The stretch keyword scales each edge image section to fill the available border-image edge region.
.frame {
border: 20px solid transparent;
border-image: url("border-pattern.png") 30 stretch;
}
Each edge section is stretched along its corresponding edge instead of being repeated as separate tiles.
When to Use stretch
Stretching works well for continuous lines, smooth gradients, and artwork that can be resized without losing its intended appearance.
Potential Distortion
Patterns containing circles, squares, or detailed symbols may become elongated when stretched across a large edge.
Default Behavior
.frame {
border-image: url("border-pattern.png") 30;
}
Because stretch is the initial value, omitting the repeat mode produces the same behavior as explicitly specifying stretch.
Stretching a Gradient
.frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 stretch;
}
A gradient border generally works well with stretching because it does not require individual pattern tiles to retain a fixed shape.
repeat Value
The repeat keyword tiles the edge image sections along the available border edges.
.frame {
border: 20px solid transparent;
border-image: url("border-pattern.png") 30 repeat;
}
The image section is repeated at its calculated tile size. Tiles that do not fit completely may be clipped.
Preserving Pattern Size
Unlike round, the repeat value does not resize tiles merely to fit an integer number along the edge.
Partial Tiles
If the available edge length is not an exact multiple of the tile length, the pattern may be clipped at the ends.
Repeating Decorative Patterns
.pattern-frame {
border: 16px solid transparent;
border-image-source: url("tile-border.png");
border-image-slice: 24;
border-image-repeat: repeat;
}
This approach is useful for patterns whose individual tile proportions should remain consistent.
Pattern Alignment
Repeated border-image tiles are positioned around the center of each edge. This can cause partial tiles to appear near the corners.
Use repeat when maintaining the original tile size is more important than fitting an exact number of complete tiles.
round Value
The round keyword repeats the edge image sections while adjusting their sizes so a whole number of tiles fits along each edge.
.frame {
border: 20px solid transparent;
border-image: url("border-pattern.png") 30 round;
}
The browser determines how many tiles fit and adjusts their length to eliminate partial tiles at the ends.
Whole Tiles
The round mode avoids clipping partial pattern tiles by resizing the repeated sections.
Tile Size Adjustment
Individual tiles may become slightly wider or narrower than their original calculated size.
Decorative Frames
.decorative-frame {
border: 18px solid transparent;
border-image: url("decorative-border.png") 30 round;
}
The pattern is repeated around the frame with complete tiles along each edge.
Responsive Widths
As the element changes size, the browser can adjust the number and dimensions of repeated tiles to maintain a complete pattern.
Round Compared With Repeat
| Mode | Result |
|---|---|
repeat |
Keeps the calculated tile size and may clip partial tiles. |
round |
Adjusts tile lengths so complete tiles fit the available edge. |
Use round when complete decorative pattern tiles are more important than preserving their exact original length.
space Value
The space keyword repeats whole edge image tiles without resizing them to fill the available edge length.
.frame {
border: 20px solid transparent;
border-image: url("border-pattern.png") 30 space;
}
The browser distributes leftover space between the tiles. If the edge cannot fit at least two complete tiles, one tile is centered.
Whole Tiles With Gaps
Unlike repeat, the space value does not clip partial tiles to fill the edge.
Preserving Tile Dimensions
The tiles retain their calculated size rather than being stretched to fit an exact number.
Decorative Symbols
.symbol-frame {
border: 18px solid transparent;
border-image-source: url("symbol-border.png");
border-image-slice: 30;
border-image-repeat: space;
}
This can be useful when the border image contains distinct decorative symbols that should remain complete and separated.
Space Compared With Round
| Mode | Result |
|---|---|
round |
Adjusts tile sizes so complete tiles fit without gaps. |
space |
Preserves tile sizes and distributes leftover space between them. |
Use space when the individual pattern elements should remain complete and their original proportions are important.
One and Two Values
The border-image-repeat property accepts either one or two repeat keywords.
One Value
.frame {
border-image-repeat: repeat;
}
All four border-image edges use repeat.
Two Values
.frame {
border-image-repeat: round stretch;
}
The top and bottom edges use round. The left and right edges use stretch.
Stretch Horizontally, Repeat Vertically
.frame {
border-image-repeat: stretch repeat;
}
The horizontal edges stretch while the vertical edges repeat.
Repeat Horizontally, Round Vertically
.frame {
border-image-repeat: repeat round;
}
The top and bottom edges use repeat, while the left and right edges use round.
Space Horizontally, Stretch Vertically
.frame {
border-image-repeat: space stretch;
}
The horizontal edges use complete spaced tiles. The vertical edges stretch their image sections.
Value Assignment Summary
| Syntax | Horizontal Edges | Vertical Edges |
|---|---|---|
stretch |
Stretch | Stretch |
repeat |
Repeat | Repeat |
round stretch |
Round | Stretch |
repeat space |
Repeat | Space |
The first value always applies to the top and bottom edges, and the second applies to the left and right edges. This assignment does not change with writing mode or text direction.
Image Slicing and Repetition
The appearance of repeated border-image sections depends on how the source image is sliced.
Using a Single Slice Value
.frame {
border: 20px solid transparent;
border-image-source: url("border-pattern.png");
border-image-slice: 30;
border-image-repeat: repeat;
}
The source is sliced 30 image units inward from each side, and the edge sections repeat around the border.
Using Different Slice Values
.frame {
border: 20px solid transparent;
border-image-source: url("border-pattern.png");
border-image-slice: 20 40;
border-image-repeat: round;
}
The top and bottom slice offsets are 20 image units, while the right and left offsets are 40 image units.
Using Percentage Slices
.frame {
border: 20px solid transparent;
border-image: url("border-pattern.png") 25% round;
}
The slice offsets are calculated as percentages of the source image dimensions.
Using fill
.frame {
border: 20px solid transparent;
border-image: url("border-pattern.png") 30 fill round;
}
The fill keyword preserves the center image section. The edge sections still use the specified repeat mode.
Corner Sections Remain Separate
The four corner sections are scaled to their corresponding corner regions. The repeat mode applies to the edge sections rather than the corners.
Choosing Slice Values
For decorative images, choose slice offsets that separate corner artwork from the repeating edge patterns.
Incorrect slice positions may cause visible seams, distorted corners, or incomplete patterns along the edges.
Border Image Shorthand
The border-image-repeat property is one of five components controlled by the border-image shorthand.
Complete Shorthand
.frame {
border-image: url("border-pattern.png") 30 / 16px / 4px round;
}
The shorthand specifies the image source, slice, painted width, outset, and repeat behavior.
Equivalent Longhand Declarations
.frame {
border-image-source: url("border-pattern.png");
border-image-slice: 30;
border-image-width: 16px;
border-image-outset: 4px;
border-image-repeat: round;
}
These declarations produce the same border-image configuration as the shorthand.
Repeat Mode in the Shorthand
.frame {
border-image: url("border-pattern.png") 30 repeat;
}
The repeat keyword sets the repeat behavior for both horizontal and vertical edges.
Two Repeat Modes in the Shorthand
.frame {
border-image: url("border-pattern.png") 30 round stretch;
}
The horizontal edges use round, while the vertical edges use stretch.
Shorthand Reset Behavior
.frame {
border-image-repeat: round;
border-image: url("border-pattern.png") 30;
}
The later shorthand resets border-image-repeat to its initial value of stretch because no repeat mode is specified.
Longhand After Shorthand
.frame {
border-image: url("border-pattern.png") 30;
border-image-repeat: round;
}
The later longhand changes the repeat mode without resetting the other border-image components.
When adjusting only the repeat behavior, a separate border-image-repeat declaration is often easier to maintain.
Image Size and Pattern Fitting
The source image, slice dimensions, border-image width, and available edge length all affect the appearance of repeated border-image patterns.
Border Image Width
.frame {
border: 12px solid transparent;
border-image: url("border-pattern.png") 30 / 20px round;
}
The painted border-image regions are 20 pixels wide. The source image sections are scaled according to the border-image sizing rules before repetition.
Repeat With a Fixed Painted Width
.frame {
border: 12px solid transparent;
border-image: url("border-pattern.png") 30 / 12px repeat;
}
The edge sections repeat using their calculated tile dimensions.
Round With a Fixed Painted Width
.frame {
border: 12px solid transparent;
border-image: url("border-pattern.png") 30 / 12px round;
}
The edge sections are resized along their repeating direction so complete tiles fit.
Different Horizontal and Vertical Modes
.frame {
border: 12px solid transparent;
border-image: url("border-pattern.png") 30 / 12px repeat round;
}
The top and bottom edges repeat at their calculated tile size. The left and right edges adjust tile lengths to fit complete repetitions.
Border Image Outset
.frame {
border: 12px solid transparent;
border-image: url("border-pattern.png") 30 / 12px / 8px round;
}
The border-image area extends 8 pixels beyond the border box. This changes the available border-image painting area but does not alter layout dimensions.
Maintaining Pattern Quality
Use source images with sufficient resolution for the intended painted border width. Raster images may become blurry when enlarged significantly.
Vector images can be useful for decorative patterns that need to remain sharp at different sizes.
Responsive Border Patterns
Border-image repeat modes can help decorative patterns adapt to different component dimensions.
Flexible Frame Width
.responsive-frame {
box-sizing: border-box;
width: 100%;
max-width: 600px;
padding: 20px;
border: 16px solid transparent;
border-image: url("border-pattern.png") 30 round;
}
The number and size of repeated tiles adjust as the element changes width.
Changing Repeat Mode With a Media Query
.responsive-frame {
border-image-repeat: round;
}
@media (max-width: 600px) {
.responsive-frame {
border-image-repeat: stretch;
}
}
The border uses rounded repetition on larger screens and stretching on smaller screens.
Changing Horizontal and Vertical Modes
.responsive-frame {
border-image-repeat: round repeat;
}
@media (max-width: 600px) {
.responsive-frame {
border-image-repeat: stretch stretch;
}
}
The repeat behavior changes independently for horizontal and vertical edges.
Container Query Adjustment
.frame-container {
container-type: inline-size;
}
.responsive-frame {
border-image-repeat: stretch;
}
@container (min-width: 500px) {
.responsive-frame {
border-image-repeat: round;
}
}
The border changes to rounded repetition when its query container reaches the specified width.
Responsive Border Thickness
.responsive-frame {
border: clamp(8px, 1.5vw, 20px) solid transparent;
border-image: url("border-pattern.png") 30 round;
}
The regular border width changes with the viewport. Because border-image-width defaults to 1, the painted border-image width follows it.
Test repeated patterns at narrow and wide sizes to check for distorted tiles, visible seams, or unwanted clipping.
Practical Uses
The border-image-repeat property is useful for decorative borders that contain patterns, symbols, or artwork requiring controlled repetition.
Continuous Decorative Frame
.continuous-frame {
padding: 20px;
border: 16px solid transparent;
border-image: url("decorative-border.png") 30 stretch;
}
The edge sections stretch continuously around the element.
Repeated Pattern Frame
.pattern-frame {
padding: 20px;
border: 16px solid transparent;
border-image: url("tile-border.png") 24 repeat;
}
The edge pattern repeats without resizing tiles merely to fit the available length.
Complete Pattern Tiles
.rounded-repeat-frame {
padding: 20px;
border: 16px solid transparent;
border-image: url("tile-border.png") 24 round;
}
The repeated tiles are adjusted to fit complete repetitions along the border edges.
Spaced Decorative Symbols
.spaced-frame {
padding: 20px;
border: 16px solid transparent;
border-image: url("symbol-border.png") 24 space;
}
The decorative symbols remain complete, with leftover space distributed between them.
Mixed Repeat Modes
.mixed-frame {
padding: 20px;
border: 16px solid transparent;
border-image: url("decorative-border.png") 30 round stretch;
}
The horizontal edges repeat with adjusted tile sizes while the vertical edges stretch.
Gradient Border
.gradient-frame {
padding: 20px;
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 stretch;
}
Stretching is a suitable choice for continuous gradient borders.
border-image-repeat Example
The following example compares all four repeat modes using the same generated SVG border pattern. Each frame uses identical slicing and border widths, allowing the repeat behavior to be compared directly.
<div class="border-repeat-demo">
<div class="demo-item">
<h3>Stretch</h3>
<div class="demo-box stretch-border">stretch</div>
</div>
<div class="demo-item">
<h3>Repeat</h3>
<div class="demo-box repeat-border">repeat</div>
</div>
<div class="demo-item">
<h3>Round</h3>
<div class="demo-box round-border">round</div>
</div>
<div class="demo-item">
<h3>Space</h3>
<div class="demo-box space-border">space</div>
</div>
</div>
.border-repeat-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 24px;
}
.border-repeat-demo .demo-item {
min-width: 0;
}
.border-repeat-demo h3 {
margin-bottom: 12px;
font-size: 1rem;
}
.border-repeat-demo .demo-box {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: 140px;
padding: 20px;
border: 18px solid transparent;
border-image-source: url("border-pattern.svg");
border-image-slice: 18;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.border-repeat-demo .stretch-border {
border-image-repeat: stretch;
}
.border-repeat-demo .repeat-border {
border-image-repeat: repeat;
}
.border-repeat-demo .round-border {
border-image-repeat: round;
}
.border-repeat-demo .space-border {
border-image-repeat: space;
}
The live preview below uses a self-contained SVG image as its border-image source, so no external image file is required.
Stretch
Repeat
Round
Space
The stretch example stretches the patterned edge sections to fill each side.
The repeat example repeats the pattern at its calculated tile size, allowing partial tiles near the corners.
The round example adjusts the tile lengths so complete repetitions fit each edge.
The space example preserves complete tiles and distributes any remaining space between them.
All four examples use the same source image and slice value. Only border-image-repeat changes.
Important Considerations
Keep the following points in mind when using border-image-repeat:
- Purpose: Controls how sliced border-image edge sections are stretched or repeated.
- Initial value: The initial repeat mode is
stretch. - Inheritance: The property is not inherited.
- Accepted values: Supports
stretch,repeat,round, andspace. - One value: Applies the same repeat mode to horizontal and vertical edges.
- Two values: Sets the horizontal mode first and vertical mode second.
- Physical edges: The first value controls top and bottom, while the second controls left and right.
- stretch: Scales each edge section to fill the available edge region.
- repeat: Repeats edge sections and may clip partial tiles.
- round: Adjusts tile lengths to fit complete repetitions.
- space: Preserves whole tiles and distributes leftover space between them.
- Corner sections: The repeat mode does not tile the four corner sections.
- Center section: The center is discarded unless
fillis specified in the slice values. - Image slicing: Slice values determine which parts of the source become corners and repeating edges.
- Image source: The property has no visible effect without a border-image source.
- Painted width:
border-image-widthinfluences the dimensions used to scale border-image sections. - Outset:
border-image-outsetcan expand the border-image painting area. - Layout: Changing the repeat mode does not change the element's box-model dimensions.
- Shorthand: The repeat mode can be specified in the
border-imageshorthand. - Shorthand resets: A later shorthand without a repeat mode resets it to
stretch. - Animation: The property is not animatable.
- Pattern quality: Detailed raster artwork may become distorted or blurry when stretched or resized.
- Browser support: Modern browsers support the standard property without vendor prefixes.
Use border-image-repeat to control whether decorative border patterns stretch continuously, repeat at their calculated size, fit as complete tiles, or retain spacing between tiles.
Browser Support
The border-image-repeat property is widely available and supported in current versions of Chrome, Edge, Firefox, Safari, and other major browsers.
The standard property does not require vendor prefixes in modern browsers.
Standard Declaration
.frame {
border: 16px solid transparent;
border-image: url("border-pattern.png") 30 round;
}
Two-Value Declaration
.frame {
border: 16px solid transparent;
border-image: url("border-pattern.png") 30 round stretch;
}
Both examples use standard CSS border-image repeat syntax.
Fallback Border
.frame {
border: 16px solid #1769aa;
border-image: url("border-pattern.png") 30 round;
}
The regular border provides a fallback if the border image cannot be used.
Visit Can I Use? and search for border-image-repeat to review browser compatibility.
Specifications
The border-image-repeat property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines the stretch, repeat, round, and space keywords and how they apply to horizontal and vertical border-image edges.
Additional border-image slicing and painting rules are defined in the same specification.
