π Introduction
The border-image property in CSS is a powerful shorthand that allows you to apply images or gradients as borders around an element. Instead of using plain solid/dashed borders, you can design decorative frames, artistic borders, patterns, or even gradient outlines. It combines **five** different border-image properties into a single declaration. π¨β¨
π― What Does border-image Control?
The shorthand border-image includes:
- border-image-source β the image/gradient used
- border-image-slice β how the image is divided
- border-image-width β thickness of the border image
- border-image-outset β how far border image extends outward
- border-image-repeat β stretch / repeat / round / space
β¨ Syntax
Shorthand Syntax
selector {
border-image: <source> <slice> / <width> / <outset> <repeat>;
}Note
border: 20px solid transparent;π§© Breaking Down the Syntax
Shorthand Parts
border-image: url(frame.png) 30 / 20px / 10px repeat;| Part | Meaning |
|---|---|
| url(frame.png) | Image source |
| 30 | Slice value |
| / 20px | Border image width |
| / 10px | Outset distance |
| repeat | How slices repeat on edges |
π₯ Simple Usage Examples
1. Basic Border Image
Basic Example
.box {
border: 20px solid transparent;
border-image: url("border.png") 30;
}2. Using Gradient as Border Image
Gradient Border
.gradient {
border: 10px solid transparent;
border-image: linear-gradient(45deg, #ff9a9e, #fad0c4) 1;
}3. Multi-Property Border Image
Full Example
.fancy {
border: 20px solid transparent;
border-image: url("decor.png") 40 / 30px / 5px round;
}4. Patterned Repeating Border
Repeat Example
.pattern {
border: 15px solid transparent;
border-image: url("pattern.png") 25 / 15px / 0 repeat;
}π§© Full Component Breakdown
1. border-image-source
Defines image or gradient used as border.
2. border-image-slice
Slices image into 9 regions (4 corners, 4 sides, center).
3. border-image-width
Controls thickness of the border image.
4. border-image-outset
Moves image outward from the element.
5. border-image-repeat
Defines how slices fill edges (stretch, repeat, round, space).
π Summary: Shorthand vs Longhand
| Property | Shorthand Equivalent |
|---|---|
| border-image | border-image-source border-image-slice border-image-width border-image-outset border-image-repeat |
π₯ Advanced Examples
1. Elegant Frame Effect
Elegant Frame
.frame {
border: 40px solid transparent;
border-image: url("frame-art.png") 50 / 40px / 15px round;
}2. Double Slice With Fill
Fill Center
.fill-center {
border: 30px solid transparent;
border-image: url("texture.png") 30 fill / 25px repeat;
}3. Mixed Repeat Behavior
Mixed Repeat
.mixed {
border: 20px solid transparent;
border-image: url("border.png") 20 / 20px / 0 repeat stretch;
}πΌοΈ Visual Demo
Further details can be found at: https://dummyimage.com/900x260/eeeeee/000000&text=border-image+demo
π Conclusion
The border-image shorthand provides complete control over image-based borders in a single clean declaration. Whether you're designing elegant frames, gradient borders, or decorative components, the combination of border-image-source, border-image-slice,border-image-width, border-image-outset, andborder-image-repeat enables endless creativity. Use this property to take your UI design to a whole new visual level. π