CSS border-image Property
The border-image property is a shorthand property that draws an element's border using an image or CSS gradient instead of a solid color.
It combines five border-image properties to control the image source, how the image is divided into sections, the width of the painted border, how far the image extends beyond the border box, and how its sections repeat or stretch. It is useful for decorative frames, gradient borders, and custom border patterns.
border-image Syntax
selector {
border-image: source slice / width / outset repeat;
}
The shorthand accepts an image source, slice values, optional width and outset values separated by slashes, and repeat behavior. Not every component is required.
Basic Image Border
.panel {
border: 20px solid transparent;
border-image: url("border-pattern.png") 30 round;
}
The image is divided using a slice value of 30. The resulting edge sections repeat around the element using the round mode.
Gradient Border
.panel {
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
A linear gradient supplies the border image. The slice value of 1 divides the gradient image for border painting.
Explicit Border Image Width
.panel {
border: 10px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 / 2;
}
The value after the slash sets border-image-width. Here, 2 means twice the corresponding computed border width.
Complete Shorthand
.panel {
border: 12px solid transparent;
border-image: url("border-pattern.png") 30 / 12px / 4px round;
}
This declaration specifies the image source, slice, painted width, outset, and repeat behavior.
CSS-Wide Keywords
.inherited {
border-image: inherit;
}
.reset {
border-image: initial;
}
.unset {
border-image: unset;
}
.reverted {
border-image: revert;
}
.layer-reverted {
border-image: revert-layer;
}
CSS-wide keywords must be used alone. They cannot be combined with individual border-image values.
Property Values
The border-image shorthand controls five individual properties.
| Component | Description |
|---|---|
border-image-source |
Specifies the image or gradient used to paint the border. |
border-image-slice |
Defines how the source image is divided into border sections. |
border-image-width |
Controls the thickness of the painted border-image regions. |
border-image-outset |
Controls how far the border image extends beyond the border box. |
border-image-repeat |
Determines whether the image sections stretch, repeat, round, or space along the border edges. |
Initial Values
| Property | Initial Value |
|---|---|
border-image-source |
none |
border-image-slice |
100% |
border-image-width |
1 |
border-image-outset |
0 |
border-image-repeat |
stretch |
When a component is omitted from the shorthand, its initial value is used. The shorthand is not inherited.
How It Works
A border image is painted by dividing a source image into nine regions. The four corners, four edges, and center can then be placed around an element.
The Nine-Slice Model
| Top-left corner | Top edge | Top-right corner |
| Left edge | Center | Right edge |
| Bottom-left corner | Bottom edge | Bottom-right corner |
The corner sections are scaled to fit the corresponding border-image corner regions. The edge sections are stretched or repeated according to border-image-repeat.
The center section is discarded by default. Adding the fill keyword to the slice values causes the center section to be painted as well.
Basic Setup
.frame {
padding: 20px;
border: 16px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 24;
border-image-repeat: stretch;
}
The source image is sliced 24 image units inward from each edge. Its corner and edge sections are used to paint the border.
Equivalent Shorthand
.frame {
padding: 20px;
border: 16px solid transparent;
border-image: url("frame.png") 24 stretch;
}
The shorthand produces the same border-image configuration as the preceding longhand declarations.
Border Style and Image Painting
Unlike a regular border, a border image can be painted even when the computed border style is none. However, the default border width is then zero, so the image may not be visible unless the border width or border-image width is established.
.frame {
border: 10px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
Using a transparent solid border is a common and predictable way to reserve space for the image border.
Border Image Components
Each longhand property controls a different part of the border-image rendering process.
border-image-source
.frame {
border-image-source: url("frame.png");
}
Specifies the image to use. CSS gradients are also valid image sources.
border-image-slice
.frame {
border-image-slice: 30;
}
Defines the slice offsets used to divide the source into nine regions.
border-image-width
.frame {
border-image-width: 12px;
}
Sets the width of the painted border-image regions. This does not change the element's computed border-width.
border-image-outset
.frame {
border-image-outset: 6px;
}
Extends the painted border image beyond the element's border box.
border-image-repeat
.frame {
border-image-repeat: round;
}
Controls how the edge sections are distributed along the border.
Combining the Longhands
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: 12px;
border-image-outset: 4px;
border-image-repeat: round;
}
These declarations provide separate control over all five border-image components.
Image Slicing
The border-image-slice component determines where the source image is cut into its nine regions.
One Slice Value
.frame {
border-image: url("frame.png") 30;
}
The value 30 applies to all four sides of the source image.
Two Slice Values
.frame {
border-image: url("frame.png") 20 40;
}
The first value applies to the top and bottom. The second applies to the right and left.
Three Slice Values
.frame {
border-image: url("frame.png") 10 20 30;
}
The values apply to the top, right and left, and bottom respectively.
Four Slice Values
.frame {
border-image: url("frame.png") 10 20 30 40;
}
The values apply in clockwise order: top, right, bottom, and left.
Percentage Slices
.frame {
border-image: url("frame.png") 25%;
}
Percentage slices are calculated relative to the dimensions of the source image. Horizontal offsets use its width, while vertical offsets use its height.
Number Slices
For raster images, number values correspond to image pixels. For vector images, they correspond to coordinates in the image's coordinate system.
Filling the Center
.frame {
border: 12px solid transparent;
border-image: url("frame.png") 30 fill;
}
The fill keyword preserves and paints the center section of the source image.
The center image is painted behind the element's content and is not a replacement for the background property.
Slicing a Gradient
.frame {
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
The slice value 1 is commonly used with gradients to produce a continuous gradient border.
Border Image Width and Outset
The border-image-width and border-image-outset components control where and how thickly the border image is painted.
Using the Computed Border Width
.frame {
border: 10px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
The initial border-image-width value is 1, so the painted image width matches the computed border width.
Setting an Explicit Image Width
.frame {
border: 10px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 / 20px;
}
The painted image border is 20 pixels wide, even though the element's computed border width remains 10 pixels.
Using a Width Multiplier
.frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 / 2;
}
The unitless value 2 multiplies the corresponding computed border width, producing a painted width of 16 pixels.
Using auto
.frame {
border: 12px solid transparent;
border-image: url("frame.png") 30 / auto;
}
The auto keyword uses the intrinsic size of the corresponding image slice when available. Otherwise, the computed border width is used.
Extending the Border Image
.frame {
border: 10px solid transparent;
border-image: url("frame.png") 30 / 10px / 6px round;
}
The border image extends 6 pixels beyond each side of the border box.
Outset Multipliers
.frame {
border: 10px solid transparent;
border-image: url("frame.png") 30 / 10px / 2 round;
}
The unitless outset value 2 means twice the corresponding computed border width, so the image extends 20 pixels beyond the border box.
Different Widths and Outsets
.frame {
border: 10px solid transparent;
border-image: url("frame.png") 30 / 10px 20px / 0 5px round;
}
The painted border-image widths are 10 pixels on the top and bottom and 20 pixels on the left and right. The outset is zero vertically and 5 pixels horizontally.
Border-image widths and outsets affect painting, not the element's layout dimensions. The regular border-width properties continue to determine the border's contribution to the box model.
Repeat Modes
The border-image-repeat component determines how the four edge sections are fitted along the border.
| Value | Behavior |
|---|---|
stretch |
Stretches each edge section to fill the available space. |
repeat |
Repeats the edge section, potentially clipping partial tiles at the ends. |
round |
Repeats the edge section and adjusts tile sizes so a whole number of tiles fits. |
space |
Repeats whole tiles and distributes leftover space between them. |
Stretch
.frame {
border-image: url("pattern.png") 30 stretch;
}
The image sections stretch to fill the corresponding edges. This is the initial repeat mode.
Repeat
.frame {
border-image: url("pattern.png") 30 repeat;
}
The image sections repeat along each edge. Partial tiles may be clipped.
Round
.frame {
border-image: url("pattern.png") 30 round;
}
The browser adjusts the size of repeated sections so an integer number of tiles fits along each edge.
Space
.frame {
border-image: url("pattern.png") 30 space;
}
The browser distributes extra space between repeated sections instead of resizing them to fit.
Two Repeat Values
.frame {
border-image: url("pattern.png") 30 round stretch;
}
The first value controls the top and bottom edges. The second controls the left and right edges.
Choose stretch for continuous artwork, repeat for tiled patterns, and round when complete repeated tiles are important.
Gradient Borders
CSS gradients can be used directly as border-image sources. This avoids the need for an external image file.
Linear Gradient Border
.gradient-frame {
padding: 20px;
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
The border transitions from blue to green.
Diagonal Gradient Border
.gradient-frame {
border: 6px solid transparent;
border-image: linear-gradient(135deg, #1769aa, #8e44ad, #27ae60) 1;
}
The gradient runs diagonally through three colors.
Conic Gradient Border
.gradient-frame {
border: 8px solid transparent;
border-image: conic-gradient(#1769aa, #27ae60, #f39c12, #1769aa) 1;
}
The conic gradient produces color changes around the border.
Repeating Linear Gradient
.gradient-frame {
border: 8px solid transparent;
border-image: repeating-linear-gradient(45deg, #1769aa 0 12px, #ffffff 12px 24px) 1;
}
The repeating gradient creates diagonal color bands around the border.
Gradient With Custom Properties
:root {
--border-start: #1769aa;
--border-end: #27ae60;
}
.gradient-frame {
border: 6px solid transparent;
border-image: linear-gradient(90deg, var(--border-start), var(--border-end)) 1;
}
Custom properties make it easy to update the border colors across multiple components.
Gradient border images are especially useful for square-cornered cards, panels, and decorative content sections.
Shorthand Order and Resets
The border-image shorthand resets omitted border-image components to their initial values.
Source and Slice
.frame {
border-image: url("frame.png") 30;
}
The repeat mode defaults to stretch, the image width defaults to 1, and the outset defaults to 0.
Source, Slice, and Repeat
.frame {
border-image: url("frame.png") 30 round;
}
The image sections are distributed using the round repeat mode.
Source, Slice, and Width
.frame {
border-image: url("frame.png") 30 / 12px;
}
The slash introduces the painted border-image width.
Source, Slice, Width, and Outset
.frame {
border-image: url("frame.png") 30 / 12px / 5px;
}
The first slash introduces the width, and the second introduces the outset.
Specifying Outset Without Width
.frame {
border-image: url("frame.png") 30 / / 5px round;
}
The empty width position retains its initial value while the outset is explicitly set to 5 pixels.
Shorthand Reset Behavior
.frame {
border-image-outset: 8px;
border-image: url("frame.png") 30 round;
}
The later shorthand resets border-image-outset to its initial value of 0 because no outset is included.
Longhand After Shorthand
.frame {
border-image: url("frame.png") 30 round;
border-image-outset: 8px;
}
The later longhand declaration changes the outset without resetting the other border-image components.
Interaction With the border Shorthand
.frame {
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border: 6px solid transparent;
}
The border shorthand sets the regular border widths, styles, and colors. It does not reset the border-image shorthand, so the previously specified border image remains in effect.
For clarity, many stylesheets establish the regular border first and then declare the border image.
Borders and Layout
A border image changes how the border is painted, but the regular border properties still determine the element's border dimensions in the box model.
Reserving Border Space
.frame {
padding: 20px;
border: 12px solid transparent;
border-image: url("frame.png") 30 round;
}
The 12-pixel border contributes to the element's layout dimensions. The border image is painted in the border-image area.
Content-Box Sizing
.frame {
box-sizing: content-box;
width: 240px;
padding: 20px;
border: 10px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
With content-box, the declared width applies to the content area. Padding and borders increase the total rendered width.
Border-Box Sizing
.frame {
box-sizing: border-box;
width: 240px;
padding: 20px;
border: 10px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
With border-box, the declared width includes the padding and regular border widths.
Painted Width Versus Layout Width
.frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 / 20px;
}
The painted border-image regions are 20 pixels wide, but the regular border contributes only 8 pixels per side to the box model.
Outset and Layout
.frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1 / 8px / 10px;
}
The border image extends beyond the border box, but the outset does not increase the element's layout dimensions or create additional space between neighboring elements.
When using large image widths or outsets, provide sufficient spacing to prevent decorative borders from overlapping nearby content.
Rounded Corners
The border-image property does not follow border-radius in the same way as a regular solid border.
Border Radius With a Border Image
.frame {
border: 8px solid transparent;
border-radius: 20px;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
The border image is not automatically clipped into rounded corners by border-radius. The gradient border may therefore appear square even though the element has a border radius.
Alternative Rounded Gradient Border
For a rounded gradient border, layered backgrounds provide more predictable results.
.rounded-gradient {
padding: 20px;
border: 6px solid transparent;
border-radius: 20px;
background:
linear-gradient(#ffffff, #ffffff) padding-box,
linear-gradient(90deg, #1769aa, #27ae60) border-box;
}
The first background layer fills the padding box. The second extends into the border box, creating a gradient border that follows the rounded corners.
Rounded Gradient With a Colored Interior
.rounded-gradient {
padding: 20px;
border: 6px solid transparent;
border-radius: 20px;
background:
linear-gradient(#e8f2fb, #e8f2fb) padding-box,
linear-gradient(135deg, #1769aa, #8e44ad) border-box;
}
The interior background can be changed independently of the gradient border.
Use border-image when custom border artwork or edge repetition is required. For rounded gradient borders, layered backgrounds are often the simpler choice.
Responsive Border Images
Border images can adapt to different element dimensions and viewport sizes.
Flexible Width
.responsive-frame {
box-sizing: border-box;
width: 100%;
max-width: 600px;
padding: 20px;
border: 12px solid transparent;
border-image: url("frame.png") 30 round;
}
The element changes width while the border-image sections adjust to the available edge lengths.
Responsive Border Thickness
.responsive-frame {
border: clamp(4px, 1vw, 12px) solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
The border thickness adjusts with the viewport width while remaining between 4 and 12 pixels.
Media Query Adjustment
.responsive-frame {
border: 12px solid transparent;
border-image: url("frame.png") 30 round;
}
@media (max-width: 600px) {
.responsive-frame {
border-width: 6px;
}
}
The computed border width becomes smaller on narrow screens. Because the border-image width defaults to 1, the painted border width changes with it.
Container Query Adjustment
.frame-container {
container-type: inline-size;
}
.responsive-frame {
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
@container (min-width: 500px) {
.responsive-frame {
border-width: 12px;
}
}
The border becomes thicker when its query container reaches the specified width.
Responsive Repeat Behavior
.responsive-frame {
border: 12px solid transparent;
border-image: url("pattern.png") 30 round;
}
@media (max-width: 600px) {
.responsive-frame {
border-image-repeat: stretch;
}
}
The border uses rounded repetition on larger screens and stretching on smaller screens.
Test image borders at several element sizes, particularly when the source contains detailed corner artwork or repeating patterns.
Practical Uses
Border images are useful when a regular solid, dashed, or dotted border does not provide the desired appearance.
Decorative Content Frame
.content-frame {
padding: 24px;
border: 18px solid transparent;
border-image: url("decorative-frame.png") 36 stretch;
}
A decorative source image supplies the corners and edges of the frame.
Gradient Highlight Panel
.highlight-panel {
padding: 20px;
border: 5px solid transparent;
border-image: linear-gradient(135deg, #1769aa, #27ae60) 1;
}
The panel receives a two-color gradient border without requiring an external image.
Patterned Border
.patterned-panel {
padding: 20px;
border: 16px solid transparent;
border-image: url("tile-pattern.png") 24 round;
}
The source image's edge sections repeat around the element, adjusting to fit the available space.
Certificate-Style Frame
.certificate {
padding: 30px;
border: 24px solid transparent;
border-image: url("certificate-border.png") 48 stretch;
}
Custom artwork provides a more detailed frame than a standard CSS border style.
Multicolor Divider Frame
.multicolor-frame {
padding: 20px;
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #8e44ad, #27ae60) 1;
}
The border transitions through three colors around the element.
Repeating Stripe Border
.striped-frame {
padding: 20px;
border: 10px solid transparent;
border-image: repeating-linear-gradient(45deg, #1769aa 0 10px, #ffffff 10px 20px) 1;
}
The repeating gradient creates a striped border pattern.
border-image Example
The following example compares a linear gradient border, a conic gradient border, and a repeating striped gradient border.
<div class="border-image-demo">
<div class="demo-item">
<h3>Linear Gradient</h3>
<div class="demo-box linear-border">Gradient Border</div>
</div>
<div class="demo-item">
<h3>Conic Gradient</h3>
<div class="demo-box conic-border">Conic Border</div>
</div>
<div class="demo-item">
<h3>Repeating Stripes</h3>
<div class="demo-box striped-border">Striped Border</div>
</div>
</div>
.border-image-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 20px;
}
.border-image-demo .demo-item {
min-width: 0;
}
.border-image-demo h3 {
margin-bottom: 12px;
font-size: 1rem;
}
.border-image-demo .demo-box {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: 140px;
padding: 20px;
border: 10px solid transparent;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.border-image-demo .linear-border {
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
.border-image-demo .conic-border {
border-image: conic-gradient(#1769aa, #27ae60, #f39c12, #1769aa) 1;
}
.border-image-demo .striped-border {
border-image: repeating-linear-gradient(45deg, #1769aa 0 10px, #ffffff 10px 20px) 1;
}
Linear Gradient
Conic Gradient
Repeating Stripes
The first example uses a linear gradient that transitions from blue to green.
The second uses a conic gradient that distributes several colors around the border.
The third uses a repeating linear gradient to create diagonal stripes.
All three examples use border-image-slice: 1 and a transparent 10-pixel border. The source image is the only component that changes.
Important Considerations
Keep the following points in mind when using border-image:
- Shorthand property: Controls the source, slice, width, outset, and repeat behavior of a border image.
- Initial source: The initial
border-image-sourcevalue isnone. - Initial slice: The initial
border-image-slicevalue is100%. - Initial width: The initial
border-image-widthvalue is1, matching the computed border width. - Initial outset: The initial
border-image-outsetvalue is0. - Initial repeat: The initial
border-image-repeatvalue isstretch. - Inheritance: The property is not inherited.
- Image sources: External images and CSS gradients can be used.
- Image slicing: The source is divided into nine regions for border painting.
- Center region: The center is discarded unless the
fillkeyword is specified. - Slice values: One to four nonnegative numbers or percentages can be used.
- Repeat modes: Supports
stretch,repeat,round, andspace. - Border space: Regular border widths determine the border's contribution to layout.
- Painted width:
border-image-widthchanges painting without changing the computed border width. - Outset: The border image can extend beyond the border box without affecting layout dimensions.
- Transparent borders: A transparent solid border is a convenient way to reserve space for a border image.
- Rounded corners:
border-radiusdoes not automatically clip border images into rounded corners. - Gradient alternatives: Layered backgrounds are often preferable for rounded gradient borders.
- Shorthand resets: Omitted border-image components reset to their initial values.
- Fallback: If a border image cannot be loaded or used, the regular border properties can provide a fallback.
- Accessibility: Do not rely on decorative border colors or patterns alone to communicate essential information.
- Browser support: Modern browsers support the standard property without vendor prefixes.
Use border-image when a border requires custom artwork, repeating patterns, or gradients that cannot be achieved conveniently with regular border styles.
Browser Support
The border-image property is widely available and supported in current versions of Chrome, Edge, Firefox, Safari, and other major browsers.
The standard shorthand does not require vendor prefixes in modern browsers.
Standard Declaration
.frame {
border: 10px solid transparent;
border-image: url("frame.png") 30 round;
}
Gradient Declaration
.frame {
border: 6px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
Both examples use standard border-image syntax.
Fallback Border
.frame {
border: 6px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
The regular border color provides a fallback when the border image cannot be used.
Visit Can I Use? and search for border-image to review browser compatibility.
Specifications
The border-image property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines image slicing, border-image widths, outsets, repetition, and the shorthand syntax.
Additional information about CSS image values and gradients is available in the CSS Images specification.
