Open In App

How to Create an Image as Border Around Element?

Last Updated : 15 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

To create an image as a border around an element, you can use the border-image CSS property, which allows an image to be used in place of a standard border.

Syntax:

border-image: url(image-path.png);

Adding Image as a Border Around an Element

  • Create a box using an <div> element in your HTML to hold the content you want.
  • Use CSS to define the box’s appearance, including its width and padding (the space inside the border).
  • Specify the border’s thickness and style. For the image border to work, you must set a border style (like solid).
  • Use the border-image property to link to your image and define how it should fit around the box, including slicing and repeating settings.
html
<!DOCTYPE html>
<html lang="en">
  
<head>
    <style>
        .image-border-box {
            width: 300px;
            padding: 20px;
            border-width: 15px; 
            border-style: solid;
            border-image: url(
'https://media.geeksforgeeks.org/wp-content/uploads/border1-2.png') 30 round; 
        }
    </style>
</head>
  
<body>
    <div class="image-border-box">
        This box has an image border!
    </div>
</body>
  
</html>

Output

Screenshot-2024-10-17-154218

Image as Border



Article Tags :

Similar Reads