CSS border-image-width Property
The border-image-width property specifies the thickness of the regions used to paint an element's border image.
It accepts one to four lengths, percentages, nonnegative numbers, or the auto keyword. Unlike the regular border-width property, border-image-width controls how the border image is painted without changing the element's box-model dimensions.
border-image-width Syntax
selector {
border-image-width: 20px;
}
The property accepts one to four values. Each value may be a nonnegative length, percentage, number, or auto.
Length Value
.frame {
border-image-width: 20px;
}
All four painted border-image regions are 20 pixels thick.
Number Value
.frame {
border-image-width: 2;
}
The painted width is twice the corresponding regular border width.
Percentage Value
.frame {
border-image-width: 10%;
}
The top and bottom widths are based on the border-image area's height. The right and left widths are based on its width.
auto Value
.frame {
border-image-width: auto;
}
The painted width is determined from the corresponding source-image slice when possible, or from the regular border width.
Two Values
.frame {
border-image-width: 10px 20px;
}
The top and bottom widths are 10 pixels. The right and left widths are 20 pixels.
Four Values
.frame {
border-image-width: 10px 20px 30px 40px;
}
The values apply clockwise to the top, right, bottom, and left regions.
Mixed Values
.frame {
border-image-width: 12px 2 15% auto;
}
Different value types may be combined within the same declaration.
CSS-Wide Keywords
.inherited {
border-image-width: inherit;
}
.reset {
border-image-width: initial;
}
.unset {
border-image-width: unset;
}
.reverted {
border-image-width: revert;
}
.layer-reverted {
border-image-width: revert-layer;
}
CSS-wide keywords must be used alone and cannot be combined with width values.
Property Values
| Value | Description |
|---|---|
<length> |
Specifies a nonnegative painted width using CSS length units such as px, em, or rem. |
<percentage> |
Specifies a nonnegative width relative to the corresponding dimension of the border-image area. |
<number> |
Specifies a nonnegative multiplier of the corresponding regular border width. |
auto |
Uses the corresponding intrinsic source-image slice thickness when available, or the regular border width otherwise. |
| One value | Applies the same value to all four sides. |
| Two values | Sets the top and bottom first, then the right and left. |
| Three values | Sets the top, right and left, then bottom. |
| Four values | Sets the top, right, bottom, and left individually. |
1 |
The initial value, making each painted width equal to its corresponding regular border width. |
CSS-Wide Keywords
| Keyword | Behavior |
|---|---|
inherit |
Uses the parent's computed border-image width values. |
initial |
Resets the property to 1. |
unset |
Resets the property to 1 because it 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 1. The property is not inherited, and compatible numeric, length, and percentage values can be animated.
How It Works
The border-image-width property controls how much space the painted border-image regions occupy around an element.
The browser first determines the border-image area, which normally matches the element's border box unless an outset is specified.
Step 1: Define the Regular Border
.frame {
border: 12px solid transparent;
}
The regular border reserves 12 pixels of layout space on each side.
Step 2: Select the Image Source
.frame {
border-image-source: url("frame.png");
}
The source image provides the artwork used to paint the border.
Step 3: Slice the Source Image
.frame {
border-image-slice: 30;
}
The source image is divided into nine sections.
Step 4: Set the Painted Width
.frame {
border-image-width: 20px;
}
The border-image regions are painted at a thickness of 20 pixels.
Step 5: Complete the Border Image
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: 20px;
border-image-repeat: round;
}
The border image is painted using 20-pixel regions, even though the regular border reserves only 12 pixels of layout space.
Changing the Painted Width
.frame {
border-image-width: 8px;
}
The painted border-image regions become thinner without changing the regular border width.
This separation allows border-image artwork to be sized independently from the element's box-model dimensions.
One to Four Values
The border-image-width property follows the clockwise assignment pattern used by CSS box-model shorthand properties.
One Value
.frame {
border-image-width: 20px;
}
All four painted border-image regions are 20 pixels thick.
Two Values
.frame {
border-image-width: 10px 20px;
}
The top and bottom widths are 10 pixels. The right and left widths are 20 pixels.
Three Values
.frame {
border-image-width: 10px 20px 30px;
}
The top width is 10 pixels, the right and left widths are 20 pixels, and the bottom width is 30 pixels.
Four Values
.frame {
border-image-width: 10px 20px 30px 40px;
}
The top, right, bottom, and left widths are 10, 20, 30, and 40 pixels respectively.
Mixed Value Types
.frame {
border-image-width: 12px 2 15% auto;
}
The top uses a fixed length, the right uses a border-width multiplier, the bottom uses a percentage, and the left uses automatic sizing.
Value Assignment Summary
| Number of Values | Assignment |
|---|---|
| 1 | All four sides |
| 2 | Top/bottom, right/left |
| 3 | Top, right/left, bottom |
| 4 | Top, right, bottom, left |
The values refer to physical sides of the border-image area and do not change based on writing mode or text direction.
Length Values
Length values specify the painted border-image width using CSS length units.
Pixel Width
.frame {
border-image-width: 20px;
}
Each painted border-image region is 20 pixels thick.
Relative Font Units
.frame {
border-image-width: 1.5em;
}
The painted width is based on the element's font size.
Root-Relative Units
.frame {
border-image-width: 1rem;
}
The painted width is based on the root element's font size.
Different Lengths
.frame {
border-image-width: 10px 20px 15px 25px;
}
Each side receives an independently specified painted width.
Zero Length
.frame {
border-image-width: 0;
}
A zero width leaves no thickness for the border-image edge regions.
Negative Lengths
.invalid {
border-image-width: -10px;
}
Negative widths are invalid and cause the declaration to be ignored.
Calculated Length
.frame {
border-image-width: calc(8px + 1vw);
}
The painted width is calculated from a fixed length and a viewport-relative length.
Length values are useful when the decorative border needs a specific painted thickness independent of the regular border width.
Number Values
Number values multiply the corresponding regular border width.
Default Multiplier
.frame {
border: 12px solid transparent;
border-image-width: 1;
}
The painted border-image width is 12 pixels, matching the regular border width.
Double the Border Width
.frame {
border: 12px solid transparent;
border-image-width: 2;
}
The painted border-image width is 24 pixels.
Half the Border Width
.frame {
border: 12px solid transparent;
border-image-width: 0.5;
}
The painted border-image width is 6 pixels.
Different Multipliers
.frame {
border: 10px solid transparent;
border-image-width: 1 2 1.5 3;
}
The painted widths are 10 pixels at the top, 20 pixels at the right, 15 pixels at the bottom, and 30 pixels at the left.
Zero Multiplier
.frame {
border-image-width: 0;
}
A zero multiplier produces zero painted width.
Negative Multiplier
.invalid {
border-image-width: -1;
}
Negative number values are invalid.
Calculated Multiplier
.frame {
border-image-width: calc(1 + 0.5);
}
The calculated value is a multiplier of 1.5.
Number values are useful when the painted border-image width should scale automatically with the regular border width.
Percentage Values
Percentage values are calculated relative to the dimensions of the border-image area.
Single Percentage
.frame {
border-image-width: 10%;
}
The top and bottom painted widths are 10% of the border-image area's height. The right and left painted widths are 10% of its width.
Two Percentages
.frame {
border-image-width: 10% 5%;
}
The top and bottom use 10% of the border-image area's height. The right and left use 5% of its width.
Four Percentages
.frame {
border-image-width: 5% 10% 15% 20%;
}
Each percentage is calculated against the corresponding dimension of the border-image area.
Mixed Percentages and Lengths
.frame {
border-image-width: 10% 20px;
}
The top and bottom use percentage-based widths, while the right and left use fixed lengths.
Percentage Versus Slice Percentage
Percentages in border-image-width refer to the border-image area. Percentages in border-image-slice refer to the source image's dimensions.
Responsive Percentage Widths
Percentage widths can change as the border-image area changes size.
Because percentages are based on the border-image area's dimensions, they may produce much thicker painted regions on larger elements.
auto Value
The auto keyword determines the painted border-image width from the corresponding source-image slice when possible.
.frame {
border-image-width: auto;
}
Automatic Width With an Image
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: auto;
}
When the source image has a corresponding intrinsic dimension, the browser can use the image's slice thickness to determine the painted width.
Automatic Width With a Gradient
.frame {
border: 12px solid transparent;
border-image-source: linear-gradient(90deg, #1769aa, #27ae60);
border-image-slice: 1;
border-image-width: auto;
}
When the source image does not provide a usable intrinsic dimension, auto falls back to the corresponding regular border width.
Mixing auto With Other Values
.frame {
border-image-width: auto 20px;
}
The top and bottom use automatic sizing. The right and left use a fixed 20-pixel width.
Four-Side Automatic Sizing
.frame {
border-image-width: auto auto 20px 10px;
}
The top and right use automatic sizing, while the bottom and left use fixed lengths.
When to Use auto
Use auto when the border artwork's source dimensions should influence the painted width.
For predictable border thickness across different source images, explicit lengths or numeric multipliers are usually easier to control.
border-image-width vs. border-width
The border-image-width and border-width properties control different aspects of an element's border.
| Property | Purpose | Affects Layout |
|---|---|---|
border-width |
Defines the regular border thickness. | Yes |
border-image-width |
Defines the painted border-image thickness. | No |
Matching Widths
.frame {
border: 12px solid transparent;
border-image-width: 1;
}
The painted border-image width matches the regular 12-pixel border width.
Wider Painted Border
.frame {
border: 12px solid transparent;
border-image-width: 24px;
}
The regular border reserves 12 pixels, but the painted border-image regions are 24 pixels thick.
Narrower Painted Border
.frame {
border: 12px solid transparent;
border-image-width: 6px;
}
The painted border-image regions are only 6 pixels thick.
Box-Sizing Considerations
.frame {
box-sizing: border-box;
width: 300px;
padding: 20px;
border: 12px solid transparent;
border-image-width: 24px;
}
The regular border participates in the element's box sizing. The painted border-image width does not increase the declared 300-pixel width.
Content Overlap
If the painted border-image width is greater than the regular border width, the image may extend farther inward and overlap the element's padding area.
Use adequate padding when decorative border artwork must remain separate from text or other content.
Border Image Slicing
The border-image-slice property determines which parts of the source image are used, while border-image-width determines how thick those parts are painted.
Source Image Slicing
.frame {
border-image-source: url("frame.png");
border-image-slice: 30;
}
The source image is divided 30 image units inward from each edge.
Painted Width
.frame {
border-image-width: 20px;
}
The selected source sections are painted into 20-pixel-wide border-image regions.
Complete Example
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: 20px;
border-image-repeat: stretch;
}
The source is sliced using 30 image units, then the resulting sections are painted into 20-pixel-wide regions.
Different Slice and Width Values
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 20 30;
border-image-width: 10px 24px;
}
The source uses separate top/bottom and right/left slice offsets, while the painted border-image regions use independent widths.
Source Units Versus Painted Units
Numeric slice values refer to source-image units. Length-based width values refer to CSS lengths in the painted element.
These values do not need to match because they control different stages of border-image rendering.
Border Image Outset
The border-image-outset property determines how far the border image extends beyond the element's border box.
No Outset
.frame {
border: 12px solid transparent;
border-image-width: 20px;
border-image-outset: 0;
}
The border-image area matches the border box.
Fixed Outset
.frame {
border: 12px solid transparent;
border-image-width: 20px;
border-image-outset: 8px;
}
The border-image area extends 8 pixels beyond the border box.
Outset Multiplier
.frame {
border: 12px solid transparent;
border-image-width: 20px;
border-image-outset: 1;
}
The outset is equal to the corresponding regular border width, or 12 pixels in this example.
Different Outsets
.frame {
border: 12px solid transparent;
border-image-width: 20px;
border-image-outset: 4px 8px;
}
The top and bottom extend 4 pixels outward, while the right and left extend 8 pixels.
Outset and Painted Width
The outset determines the outer boundary of the border-image area. The painted width determines how far the border-image regions extend inward from that boundary.
Neither property changes the element's box-model dimensions.
Border Image Repetition
The border-image-repeat property controls how the sliced source-image sections fill the border-image regions.
Stretch
.frame {
border-image-width: 20px;
border-image-repeat: stretch;
}
The edge sections stretch to fill the available regions.
Repeat
.frame {
border-image-width: 20px;
border-image-repeat: repeat;
}
The edge sections repeat at their calculated tile sizes. Partial tiles may be clipped.
Round
.frame {
border-image-width: 20px;
border-image-repeat: round;
}
The edge tiles are resized to fit complete repetitions.
Space
.frame {
border-image-width: 20px;
border-image-repeat: space;
}
Complete edge tiles are repeated with leftover space distributed between them.
Different Horizontal and Vertical Modes
.frame {
border-image-width: 20px;
border-image-repeat: round stretch;
}
The top and bottom edges use rounded repetition, while the left and right edges stretch.
Width and Tile Scaling
The painted border-image width influences how source sections are scaled before they are stretched or repeated along the edges.
Changing the width can therefore change the apparent size of repeated border patterns.
Border Image Shorthand
The border-image-width property is one of five components controlled by the border-image shorthand.
Basic Shorthand
.frame {
border-image: url("frame.png") 30 / 20px round;
}
The value after the first slash specifies the painted border-image width.
Complete Shorthand
.frame {
border-image: url("frame.png") 30 / 20px / 8px round;
}
The shorthand specifies the image source, slice, painted width, outset, and repeat mode.
Equivalent Longhand Declarations
.frame {
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: 20px;
border-image-outset: 8px;
border-image-repeat: round;
}
These declarations produce the same border-image configuration as the complete shorthand.
Numeric Width in Shorthand
.frame {
border: 12px solid transparent;
border-image: url("frame.png") 30 / 2 round;
}
The painted border-image width is twice the regular border width.
Automatic Width in Shorthand
.frame {
border-image: url("frame.png") 30 / auto round;
}
The painted width is determined automatically.
Shorthand Reset Behavior
.frame {
border-image-width: 20px;
border-image: url("frame.png") 30 round;
}
The later shorthand resets border-image-width to its initial value of 1 because no width is specified.
Longhand After Shorthand
.frame {
border-image: url("frame.png") 30 round;
border-image-width: 20px;
}
The later longhand changes only the painted width.
Use the longhand property when adjusting the border-image thickness without changing the source, slice, outset, or repeat mode.
Gradients and Images
The border-image-width property works with both external image files and CSS-generated images.
Raster Image Border
.raster-frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: 20px;
}
The raster image sections are painted into 20-pixel-wide regions.
SVG Image Border
.svg-frame {
border: 12px solid transparent;
border-image-source: url("frame.svg");
border-image-slice: 20;
border-image-width: 24px;
}
The SVG artwork is painted into 24-pixel-wide border-image regions.
Linear Gradient Border
.gradient-frame {
border: 8px solid transparent;
border-image-source: linear-gradient(90deg, #1769aa, #27ae60);
border-image-slice: 1;
border-image-width: 12px;
}
The gradient is painted using 12-pixel-wide border-image regions.
Conic Gradient Border
.conic-frame {
border: 8px solid transparent;
border-image-source: conic-gradient(#1769aa, #27ae60, #8e44ad, #1769aa);
border-image-slice: 1;
border-image-width: 16px;
}
The conic gradient creates a multicolored border with a painted width of 16 pixels.
Repeating Gradient Border
.striped-frame {
border: 8px solid transparent;
border-image-source: repeating-linear-gradient(45deg, #1769aa 0 10px, #ffffff 10px 20px);
border-image-slice: 1;
border-image-width: 14px;
}
The repeating gradient creates a striped border painted into 14-pixel-wide regions.
Image Quality
Increasing the painted width can enlarge raster artwork and make it appear blurry if the source image has insufficient resolution.
SVG images and CSS gradients are useful when border artwork needs to remain sharp at different painted widths.
Responsive Border Images
The painted border-image width can respond to viewport size, font size, or container dimensions.
Viewport-Relative Width
.responsive-frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 1vw;
}
The painted width changes with the viewport width.
Clamped Width
.responsive-frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: clamp(6px, 1vw, 16px);
}
The painted width adjusts with the viewport while remaining between 6 and 16 pixels.
Media Query
.responsive-frame {
border: 12px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 16px;
}
@media (max-width: 600px) {
.responsive-frame {
border-image-width: 8px;
}
}
The painted border-image width becomes thinner on smaller screens.
Container Query
.frame-container {
container-type: inline-size;
}
.responsive-frame {
border-image-width: 8px;
}
@container (min-width: 500px) {
.responsive-frame {
border-image-width: 16px;
}
}
The painted width changes when the query container reaches the specified size.
Relative Font Units
.responsive-frame {
border-image-width: 1em;
}
The painted width scales with the element's font size.
Use responsive widths when decorative borders should become thinner on smaller elements or screens without changing the underlying layout border.
Practical Uses
The border-image-width property is useful for decorative frames, gradient borders, image-based panels, and responsive border effects.
Thick Decorative Frame
.decorative-frame {
padding: 24px;
border: 12px solid #1769aa;
border-image-source: url("decorative-frame.png");
border-image-slice: 30;
border-image-width: 24px;
border-image-repeat: round;
}
The decorative artwork is painted into 24-pixel-wide regions while the regular border remains 12 pixels wide.
Thin Gradient Border
.thin-gradient {
padding: 20px;
border: 8px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 4px;
}
The gradient is painted into narrow 4-pixel-wide regions.
Wide Gradient Border
.wide-gradient {
padding: 20px;
border: 8px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 16px;
}
The gradient is painted into wider 16-pixel regions.
Asymmetric Border
.asymmetric-frame {
padding: 24px;
border: 12px solid #1769aa;
border-image: linear-gradient(135deg, #1769aa, #27ae60) 1;
border-image-width: 8px 16px 24px 32px;
}
The top, right, bottom, and left painted regions have different widths.
Border Width Multiplier
.multiplier-frame {
padding: 20px;
border: 10px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 1.5;
}
The painted border-image width is 1.5 times the regular border width.
Responsive Decorative Border
.responsive-frame {
padding: 20px;
border: 10px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: clamp(6px, 1vw, 16px);
}
The painted border-image width adjusts with viewport size while remaining within a defined range.
border-image-width Example
The following example compares three painted border-image widths using the same gradient source. Each element has an 8-pixel regular border, but the border-image widths are different.
<div class="border-width-demo">
<div class="demo-item">
<h3>Width: 4px</h3>
<div class="demo-box width-small">4px</div>
</div>
<div class="demo-item">
<h3>Width: 8px</h3>
<div class="demo-box width-medium">8px</div>
</div>
<div class="demo-item">
<h3>Width: 16px</h3>
<div class="demo-box width-large">16px</div>
</div>
</div>
.border-width-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 24px;
}
.border-width-demo .demo-item {
min-width: 0;
}
.border-width-demo h3 {
margin-bottom: 12px;
font-size: 1rem;
}
.border-width-demo .demo-box {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: 140px;
padding: 24px;
border: 8px solid transparent;
border-image-source: linear-gradient(135deg, #1769aa, #27ae60);
border-image-slice: 1;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.border-width-demo .width-small {
border-image-width: 4px;
}
.border-width-demo .width-medium {
border-image-width: 8px;
}
.border-width-demo .width-large {
border-image-width: 16px;
}
The live preview demonstrates how changing the painted border-image width affects the border's appearance without changing the regular border width.
Width: 4px
Width: 8px
Width: 16px
The first example paints the gradient border into 4-pixel-wide regions, making it thinner than the regular border.
The second example uses an 8-pixel painted width, matching the regular border width.
The third example uses a 16-pixel painted width, causing the gradient border to extend farther inward.
All three elements use the same source image, slice value, and regular border width. Only border-image-width changes.
Important Considerations
Keep the following points in mind when using border-image-width:
- Purpose: Controls the thickness of the painted border-image regions.
- Initial value: The initial value is
1. - Inheritance: The property is not inherited.
- Accepted values: Supports nonnegative lengths, percentages, numbers, and
auto. - One to four values: Allows separate top, right, bottom, and left painted widths.
- Length values: Specify painted widths using CSS length units.
- Number values: Multiply the corresponding regular border width.
- Percentage values: Are relative to the corresponding dimensions of the border-image area.
- auto: Uses source-image slice dimensions when available, or the regular border width otherwise.
- Negative values: Negative widths are invalid.
- Zero values: A zero width leaves no thickness for the corresponding painted region.
- Layout: The property does not change the element's box-model dimensions.
- Regular border:
border-widthcontinues to control the regular border's layout thickness. - Source image: A border-image source is needed for visible border-image painting.
- Image slicing:
border-image-slicedetermines which source-image sections are used. - Outset:
border-image-outsetcontrols how far the border-image area extends outward. - Repetition:
border-image-repeatdetermines how edge sections stretch or repeat. - Content overlap: Large painted widths may extend inward over the padding area.
- Raster quality: Enlarged raster artwork may appear blurry.
- Gradients and SVG: Can provide sharp border artwork at different painted widths.
- Shorthand: The property can be specified through
border-image. - Shorthand resets: A later
border-imageshorthand without a width resets it to1. - Animation: Compatible width values can be interpolated.
- Browser support: Modern browsers support the standard property without vendor prefixes.
Use border-image-width when the painted border-image thickness needs to differ from the regular border width or when decorative border artwork must be sized independently from the element's layout.
Browser Support
The border-image-width 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.
Length Declaration
.frame {
border: 12px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 20px;
}
Number Declaration
.frame {
border: 12px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 2;
}
Percentage Declaration
.frame {
border: 12px solid #1769aa;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
border-image-width: 10%;
}
All three examples use standard CSS border-image syntax.
Fallback Border
.frame {
border: 12px solid #1769aa;
border-image: url("frame.png") 30 / 20px round;
}
The regular border provides a visible fallback if the image resource cannot be used.
Visit Can I Use? and search for border-image-width to review browser compatibility.
Specifications
The border-image-width property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines the accepted length, percentage, number, and auto values, along with how the painted border-image widths are calculated.
Related source-image slicing, outset, and repetition rules are defined in the same specification.
