CSS border-image-slice Property
The border-image-slice property specifies how a border image is divided into nine sections for painting an element's corners, edges, and optional center.
It accepts one to four nonnegative numbers or percentages that define inward slice offsets from the source image's edges. The optional fill keyword also paints the center section. This property is used with border-image-source, border-image-width, and border-image-repeat to create decorative borders.
border-image-slice Syntax
selector {
border-image-slice: 30;
}
The property accepts one to four numbers or percentages, optionally combined with the fill keyword.
Single Number
.frame {
border-image-slice: 30;
}
The source image is sliced 30 image units inward from all four edges.
Single Percentage
.frame {
border-image-slice: 25%;
}
The source image is sliced inward by 25% of its corresponding dimensions.
Two Values
.frame {
border-image-slice: 20 40;
}
The top and bottom offsets are 20 image units. The right and left offsets are 40 image units.
Four Values
.frame {
border-image-slice: 10 20 30 40;
}
The values apply clockwise to the top, right, bottom, and left source-image edges.
Using fill
.frame {
border-image-slice: 30 fill;
}
The source is sliced 30 image units inward, and the center section is also painted.
fill Before the Values
.frame {
border-image-slice: fill 30;
}
The fill keyword may appear before or after the slice values.
CSS-Wide Keywords
.inherited {
border-image-slice: inherit;
}
.reset {
border-image-slice: initial;
}
.unset {
border-image-slice: unset;
}
.reverted {
border-image-slice: revert;
}
.layer-reverted {
border-image-slice: revert-layer;
}
CSS-wide keywords must be used alone and cannot be combined with slice values or fill.
Property Values
| Value | Description |
|---|---|
<number> |
Specifies a nonnegative slice offset in image units for raster images or vector coordinates for vector images. |
<percentage> |
Specifies a nonnegative slice offset relative to the source image's corresponding dimension. |
fill |
Preserves and paints the center image section in addition to the corners and edges. |
| One value | Applies the same slice value to all four edges. |
| 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. |
100% |
The initial value, applied to all four source-image edges. |
CSS-Wide Keywords
| Keyword | Behavior |
|---|---|
inherit |
Uses the parent's computed slice values. |
initial |
Resets the property to 100% without fill. |
unset |
Resets the property to 100% 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 100%. The property is not inherited and is animatable as a value list when compatible slice values are interpolated.
How It Works
The border-image-slice property determines where four imaginary lines are placed across a source image.
Two horizontal lines and two vertical lines divide the source into nine sections.
Source Image
A border image may be a raster image, SVG image, or CSS-generated image such as a gradient.
.frame {
border-image-source: url("decorative-frame.png");
}
Slice Offsets
.frame {
border-image-slice: 30;
}
The slice lines are positioned 30 image units inward from each edge of the source.
Corner Sections
The four corner sections are used to paint the corresponding corners of the border-image area.
Edge Sections
The top, right, bottom, and left sections are stretched or repeated along their corresponding edges according to border-image-repeat.
Center Section
The center section is normally discarded. Adding fill causes the center to be painted as well.
Complete Border Image
.frame {
border: 20px solid transparent;
border-image-source: url("decorative-frame.png");
border-image-slice: 30;
border-image-repeat: round;
}
The image is divided into nine sections. Its corners are positioned at the element's corners, and its edges repeat with adjusted tile sizes.
Changing the slice values changes which parts of the source image become corners, edges, and the center.
Nine-Slice Grid
The nine-slice grid is the foundation of CSS border-image painting.
| Top-left | Top edge | Top-right |
|---|---|---|
| Left edge | Center | Right edge |
| Bottom-left | Bottom edge | Bottom-right |
Corner Regions
The four corner regions are scaled into the corresponding corners of the border-image area.
Edge Regions
The edge regions fill the space between the corners. They may stretch, repeat, round, or space according to border-image-repeat.
Center Region
The center region is discarded unless the fill keyword is present.
Example With a 120-Pixel Image
.frame {
border-image-slice: 20;
}
For a 120 by 120 pixel raster image, the slice lines are placed 20 pixels inward from each edge.
The resulting grid contains 20-pixel-wide corner regions, edge strips, and an 80 by 80 pixel center region.
Example With Unequal Offsets
.frame {
border-image-slice: 10 20 30 40;
}
The source is sliced 10 units from the top, 20 from the right, 30 from the bottom, and 40 from the left.
Unequal slice values are useful when a source image has different corner or edge artwork on each side.
One to Four Values
The border-image-slice property follows the same clockwise value assignment pattern used by several CSS box-model shorthand properties.
One Value
.frame {
border-image-slice: 30;
}
All four slice offsets are 30 image units.
Two Values
.frame {
border-image-slice: 20 40;
}
The top and bottom offsets are 20 image units. The right and left offsets are 40 image units.
Three Values
.frame {
border-image-slice: 10 20 30;
}
The top offset is 10, the right and left offsets are 20, and the bottom offset is 30.
Four Values
.frame {
border-image-slice: 10 20 30 40;
}
The top, right, bottom, and left offsets are 10, 20, 30, and 40 image units respectively.
Mixed Numbers and Percentages
.frame {
border-image-slice: 20 15% 30 10%;
}
The top and bottom use numeric offsets. The right and left use percentages of the source image width.
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 slice offsets always refer to the physical edges of the source image. They do not change based on writing mode or text direction.
Number Values
Number values specify nonnegative slice offsets without CSS length units.
Raster Image
.frame {
border-image-source: url("frame.png");
border-image-slice: 30;
}
For a raster image, the number 30 represents 30 source-image pixels.
SVG Image
.frame {
border-image-source: url("frame.svg");
border-image-slice: 30;
}
For a vector image, number values refer to the image's coordinate system rather than CSS pixels.
Fractional Numbers
.frame {
border-image-slice: 12.5;
}
Fractional nonnegative numbers are allowed.
Zero Value
.frame {
border-image-slice: 0;
}
A zero slice offset places the slice lines at the source image's outer edges. This generally leaves no usable corner or edge image sections.
Negative Values
.invalid {
border-image-slice: -10;
}
Negative slice values are invalid and cause the declaration to be ignored.
Numbers Are Not CSS Lengths
.invalid {
border-image-slice: 30px;
}
CSS length units such as px, em, and rem are not accepted by border-image-slice.
Use unitless numbers or percentages instead.
Percentage Values
Percentage values specify slice offsets relative to the source image's dimensions.
Single Percentage
.frame {
border-image-slice: 25%;
}
The top and bottom offsets are 25% of the source image height. The right and left offsets are 25% of its width.
Two Percentages
.frame {
border-image-slice: 20% 30%;
}
The top and bottom use 20% of the source image height. The right and left use 30% of its width.
Four Percentages
.frame {
border-image-slice: 10% 20% 30% 40%;
}
Each percentage is calculated against the corresponding source-image dimension.
Mixed Values
.frame {
border-image-slice: 20 25% 30 15%;
}
Numbers and percentages may be combined in the same declaration.
Percentages With Different Image Dimensions
For a 200 by 100 pixel image, 25% produces a 25-pixel top and bottom offset and a 50-pixel right and left offset.
Percentages Greater Than 100%
.frame {
border-image-slice: 120%;
}
Percentages greater than 100% are permitted. Slice offsets that extend beyond the image dimensions are clamped to the corresponding image boundaries.
Responsive Source Images
Percentage slices can be useful when different source images share the same relative border design but have different pixel dimensions.
Percentages are based on the source image, not the element's width or height.
fill Keyword
The fill keyword causes the center section of the sliced image to be painted instead of discarded.
Without fill
.frame {
border: 20px solid transparent;
border-image: url("frame.png") 30;
}
The four corners and four edge sections are used. The center section is discarded.
With fill
.frame {
border: 20px solid transparent;
border-image: url("frame.png") 30 fill;
}
The center section is painted in addition to the corners and edges.
fill Before Slice Values
.frame {
border-image-slice: fill 30;
}
The fill keyword can appear before the slice values.
fill After Slice Values
.frame {
border-image-slice: 30 fill;
}
This produces the same result as placing fill first.
fill With Percentages
.frame {
border-image-slice: 25% fill;
}
The source is sliced using percentages, and its center section is preserved.
Center Painting and Backgrounds
The filled center is painted as part of the border image, above the element's background. Depending on the source image's transparency, it may cover the background beneath it.
Center Painting and Content
The filled center is painted below the element's content, so text and other content remain visible above it.
When to Use fill
Use fill when the source image contains a complete panel design, including a decorative center area.
Omit fill when only the border artwork should be painted and the element's background should remain independent.
Slice and Repeat
The border-image-slice and border-image-repeat properties work together to determine how the source image is divided and painted.
Stretching Edge Sections
.frame {
border: 20px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-repeat: stretch;
}
The edge sections stretch to fill the available border-image edge regions.
Repeating Edge Sections
.frame {
border: 20px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-repeat: repeat;
}
The edge sections repeat as tiles. Partial tiles may be clipped at the ends.
Rounded Repetition
.frame {
border: 20px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-repeat: round;
}
The edge tiles are resized to fit complete repetitions.
Spaced Repetition
.frame {
border: 20px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-repeat: space;
}
Complete tiles are repeated with leftover space distributed between them.
Different Horizontal and Vertical Modes
.frame {
border: 20px solid transparent;
border-image: url("frame.png") 30 round stretch;
}
The top and bottom edge sections use rounded repetition. The left and right sections stretch.
Changing the slice offsets changes the source sections being repeated. Changing the repeat mode changes how those sections fit the border-image area.
Slice and Border Image Width
The border-image-slice and border-image-width properties control different stages of border-image painting.
| Property | Purpose |
|---|---|
border-image-slice |
Defines where the source image is divided into sections. |
border-image-width |
Defines the thickness of the painted border-image regions. |
border-width |
Defines the regular border width used by the box model. |
Changing Slice Offsets
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
}
The source image is sliced 30 image units inward from each edge.
Changing Painted Border Width
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 30;
border-image-width: 20px;
}
The same source sections are used, but the painted border-image regions are 20 pixels wide.
Using Both Properties
.frame {
border: 12px solid transparent;
border-image-source: url("frame.png");
border-image-slice: 20 30;
border-image-width: 16px 24px;
}
The source image uses different vertical and horizontal slice offsets, while the painted border-image regions use separate top/bottom and right/left widths.
Independent Layout Dimensions
Changing border-image-slice does not change the element's computed border width, padding, or content dimensions.
The slice values determine which source-image regions are used. The border-image width determines how thick those regions appear when painted.
Border Image Shorthand
The border-image-slice property is one of five components controlled by the border-image shorthand.
Basic Shorthand
.frame {
border-image: url("frame.png") 30 round;
}
The source image is sliced 30 image units inward, and its edge sections use rounded repetition.
Complete Shorthand
.frame {
border-image: url("frame.png") 30 / 16px / 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: 16px;
border-image-outset: 8px;
border-image-repeat: round;
}
These declarations produce the same border-image configuration as the complete shorthand.
Shorthand With fill
.frame {
border-image: url("frame.png") 30 fill / 16px round;
}
The center section is painted along with the border-image corners and edges.
Shorthand Reset Behavior
.frame {
border-image-slice: 20;
border-image: url("frame.png");
}
The later shorthand resets border-image-slice to its initial value of 100% because no slice value is specified.
Longhand After Shorthand
.frame {
border-image: url("frame.png") 30 round;
border-image-slice: 20;
}
The later longhand changes only the slice values. The source, width, outset, and repeat mode remain unchanged.
Use a separate border-image-slice declaration when you need to adjust slicing without rewriting the entire shorthand.
Image Dimensions and Scaling
Slice values are interpreted using the source image's dimensions or coordinate system.
Raster Image Dimensions
For a 200 by 100 pixel raster image, a slice value of 20 represents 20 source-image pixels on each side.
.frame {
border-image-slice: 20;
}
Percentage-Based Slices
.frame {
border-image-slice: 20%;
}
For the same 200 by 100 pixel image, the top and bottom offsets are 20 pixels, while the right and left offsets are 40 pixels.
SVG Images
.frame {
border-image-source: url("frame.svg");
border-image-slice: 20;
}
Numeric slice values for SVG images use the image's coordinate system. Percentages provide a dimension-relative alternative.
Slice Offsets Beyond Image Boundaries
.frame {
border-image-slice: 200;
}
If a slice offset exceeds the corresponding source-image dimension, it is clamped to the image boundary.
Overlapping Slice Regions
If opposite slice offsets would overlap, the browser adjusts their positions according to the border-image slicing rules so the regions do not cross.
Image Resolution
Raster source images should have sufficient resolution for the intended painted border width. Enlarging a small source image can make detailed artwork appear blurry.
Vector Images
SVG images can be useful for decorative borders that need to remain sharp at different sizes.
Choose slice values based on the actual artwork rather than the element's final dimensions.
Gradients and Generated Images
CSS gradients can be used as border-image sources without requiring external image files.
Linear Gradient Border
.gradient-frame {
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
A slice value of 1 is commonly used with gradients to create a continuous gradient border.
Explicit Gradient Slice
.gradient-frame {
border: 8px solid transparent;
border-image-source: linear-gradient(90deg, #1769aa, #27ae60);
border-image-slice: 1;
}
The gradient supplies the source image, and the slice value determines how it is divided.
Conic Gradient Border
.gradient-frame {
border: 8px solid transparent;
border-image: conic-gradient(#1769aa, #27ae60, #8e44ad, #1769aa) 1;
}
A conic gradient can produce a multicolored border with different colors around the element.
Repeating Linear Gradient
.striped-frame {
border: 10px solid transparent;
border-image: repeating-linear-gradient(45deg, #1769aa 0 10px, #ffffff 10px 20px) 1;
}
The repeating gradient produces a striped border pattern.
Gradient With fill
.filled-frame {
border: 10px solid transparent;
border-image: linear-gradient(135deg, #1769aa, #27ae60) 1 fill;
}
The gradient also paints the center section, potentially covering the element's background.
Gradients and Border Radius
Border images do not follow the curved clipping behavior of border-radius in the same way as regular borders. For rounded gradient borders, a layered-background technique may be more appropriate.
Gradients are useful when a border needs color transitions without relying on external image assets.
Practical Uses
The border-image-slice property is useful for image-based frames, decorative panels, patterned borders, and gradient effects.
Decorative Image Frame
.decorative-frame {
padding: 20px;
border: 20px solid transparent;
border-image: url("decorative-frame.png") 30 round;
}
The image is divided into corner and edge sections, allowing the frame to adapt to the element's dimensions.
Asymmetric Frame
.asymmetric-frame {
padding: 20px;
border: 20px solid transparent;
border-image-source: url("asymmetric-frame.png");
border-image-slice: 15 30 25 40;
border-image-repeat: stretch;
}
Different slice offsets accommodate artwork with unequal border regions.
Percentage-Based Frame
.percentage-frame {
padding: 20px;
border: 20px solid transparent;
border-image: url("decorative-frame.png") 20% round;
}
Percentage offsets divide the source image according to its dimensions.
Filled Decorative Panel
.filled-panel {
padding: 24px;
border: 20px solid transparent;
border-image: url("decorative-panel.png") 30 fill stretch;
}
The center section is preserved, allowing the source image to provide both the border and the panel background.
Gradient Border
.gradient-frame {
padding: 20px;
border: 8px solid transparent;
border-image: linear-gradient(90deg, #1769aa, #27ae60) 1;
}
A simple slice value creates a gradient border without an external image.
Responsive Decorative Frame
.responsive-frame {
box-sizing: border-box;
width: 100%;
max-width: 600px;
padding: 20px;
border: 16px solid transparent;
border-image: url("decorative-frame.png") 25% round;
}
The border-image sections adapt to the element's changing dimensions while the slice percentages remain based on the source image.
border-image-slice Example
The following example compares different slice values using the same decorative SVG source. The first frame uses a smaller slice, the second uses a larger slice, and the third preserves the center section with fill.
<div class="border-slice-demo">
<div class="demo-item">
<h3>Slice: 12</h3>
<div class="demo-box slice-small">12</div>
</div>
<div class="demo-item">
<h3>Slice: 24</h3>
<div class="demo-box slice-large">24</div>
</div>
<div class="demo-item">
<h3>Slice: 24 fill</h3>
<div class="demo-box slice-filled">24 fill</div>
</div>
</div>
.border-slice-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 24px;
}
.border-slice-demo .demo-item {
min-width: 0;
}
.border-slice-demo h3 {
margin-bottom: 12px;
font-size: 1rem;
}
.border-slice-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("decorative-frame.svg");
border-image-repeat: stretch;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.border-slice-demo .slice-small {
border-image-slice: 12;
}
.border-slice-demo .slice-large {
border-image-slice: 24;
}
.border-slice-demo .slice-filled {
border-image-slice: 24 fill;
}
The live preview uses a self-contained SVG image, so no external image file is required.
Slice: 12
Slice: 24
Slice: 24 fill
The first frame uses a 12-unit slice, selecting narrower sections near the source image's outer edges.
The second frame uses a 24-unit slice, selecting larger corner and edge sections.
The third frame uses the same 24-unit slice but includes fill, causing the source image's center section to be painted.
All three frames use the same source image, border width, and repeat mode. Only border-image-slice changes.
Important Considerations
Keep the following points in mind when using border-image-slice:
- Purpose: Divides a border-image source into nine sections.
- Initial value: The initial value is
100%. - Inheritance: The property is not inherited.
- Accepted values: Supports nonnegative numbers and percentages.
- One to four values: Allows separate top, right, bottom, and left slice offsets.
- Number values: Use source-image units rather than CSS length units.
- Percentage values: Are relative to the source image's corresponding dimensions.
- CSS lengths: Values such as
20pxare invalid. - Negative values: Negative slice values are invalid.
- fill: Preserves and paints the center image section.
- Default center behavior: The center section is discarded unless
fillis present. - Corner sections: Are used to paint the four border-image corners.
- Edge sections: Are stretched or repeated according to
border-image-repeat. - Source dimensions: Determine how numeric and percentage slice values are interpreted.
- Clamping: Slice offsets beyond the source-image boundaries are clamped.
- Image source: The property has no visible effect without a border-image source.
- Border width: The regular border width determines layout space, not the slice values.
- Painted width:
border-image-widthcontrols the thickness of the painted border-image regions. - Outset:
border-image-outsetcan extend the painted image beyond the border box. - Shorthand: The property can be specified through
border-image. - Shorthand resets: A later
border-imageshorthand without a slice resets it to100%. - Animation: Compatible slice values can be interpolated.
- Browser support: Modern browsers support the standard property without vendor prefixes.
Use border-image-slice to select the correct source-image regions for decorative corners, repeating edges, and optional center artwork.
Browser Support
The border-image-slice 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: 20px solid transparent;
border-image: url("frame.png") 30 round;
}
Percentage Declaration
.frame {
border: 20px solid transparent;
border-image: url("frame.png") 25% round;
}
Declaration With fill
.frame {
border: 20px solid transparent;
border-image: url("frame.png") 30 fill round;
}
All three examples use standard CSS border-image syntax.
Fallback Border
.frame {
border: 20px solid #1769aa;
border-image: url("frame.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-slice to review browser compatibility.
Specifications
The border-image-slice property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines the numeric and percentage slice values, the optional fill keyword, and the nine-section image slicing process.
Related border-image painting and sizing rules are covered in the same specification.
