How to create Border Images in CSS?

The CSS border-image property allows you to use an image as a border around an element instead of the standard solid, dashed, or dotted borders. This creates visually appealing decorative borders using custom graphics.

Syntax

border-image: source slice width outset repeat;

Border Image Properties

The border-image property is a shorthand for the following individual properties −

Property Description
border-image-source The source of the image to be used as border
border-image-slice How to slice the border image into sections (corners, edges, middle)
border-image-width The width of the border image
border-image-outset Extends the border image area beyond the border box
border-image-repeat How to repeat, round, or stretch the border image

Example: Creating Border Images

The following example demonstrates how to apply image borders to paragraphs using different border images and slice values −

<!DOCTYPE html>
<html>
<head>
<style>
    body {
        font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
        margin: 20px;
    }
    
    .border1 {
        border: 15px solid transparent;
        padding: 20px;
        margin: 20px 0;
        border-image: url("/css/images/border-image.png") 30 round;
        background: #f9f9f9;
    }
    
    .border2 {
        border: 12px solid transparent;
        padding: 20px;
        margin: 20px 0;
        border-image: url("/css/images/border-image2.png") 20 stretch;
        background: #fff;
    }
    
    .border3 {
        border: 10px solid transparent;
        padding: 20px;
        margin: 20px 0;
        border-image: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4) 1;
        background: #fafafa;
    }
</style>
</head>
<body>
    <h1>Border Images in CSS</h1>
    
    <p class="border1">This paragraph has a decorative image border with rounded repeat pattern. The border image is sliced and repeated around the element.</p>
    
    <p class="border2">This paragraph uses a different border image with stretch repeat pattern. The image is stretched to fill the border space.</p>
    
    <p class="border3">This paragraph uses a gradient as the border image source, creating a colorful border effect around the text content.</p>
</body>
</html>
Three paragraphs are displayed with different decorative border styles:
1. First paragraph with a patterned image border using round repeat
2. Second paragraph with a stretched image border pattern  
3. Third paragraph with a colorful gradient border effect
Each paragraph has padding and different background colors to highlight the border effects.

Border Image Repeat Values

Value Description
stretch The image is stretched to fill the area (default)
repeat The image is tiled to fill the area
round The image is tiled and scaled to fit the area
space The image is tiled with spacing to fit the area

Conclusion

The border-image property provides a powerful way to create decorative borders using images or gradients. Remember to set a transparent border width first, then apply the border image for the best visual results.

Updated on: 2026-03-15T15:07:28+05:30

255 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements